Display Cross-domain feed RSS in Wordpress site

2019-06-14 12:49发布

I need to display cross-domain feeds-rss (XML format)in my site, but i get a error because ajax cross-domain call are not allowed. I've been told about json-p...anyone knows how to use or have some good tutorial?

Thanks

1条回答
smile是对你的礼貌
2楼-- · 2019-06-14 13:16

the simplest way is just to create an widget for wordpress or download some kind of like your requirement.

Because json-p load data in JSON format if you want to get data from JSON format then the given link will help you :

getJSON ajax

or you can access the rss feed with php like given example :

$xml = 'http://blog.webtech11.com/feed';
                $doc = new DOMDocument();
                $doc->load($xml);
                $item = $doc->getElementsByTagName('item');

                //$data = array();

                for($i=0; $i<=3; $i++){
                    $title = $item->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
                    $link = $item->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
                    echo '<a href="' . $link . '" target="_blank"><h2>' . $title . '</h2></a>';
                }

in this example i access latest 4 blog entries..

hope this will help you

查看更多
登录 后发表回答