Pages

Saturday, December 19, 2009

How to show RSS feeds in a Wordpress Page and Posts

Most of the bloggers having different blogs (on same or other domain) wants to aggregate the updates on the same page. If you wants to show different blogs latest post links on a wordpress page then its very easy to show rss feeds within wordpress with the help of simplexml. The following codes displays the feeds from the single feed url.

How to show rss feeds in wordrpress pages
How to show rss feeds in wordrpress pages

$xml_file = 'http://feeds.feedburner.com/honeytechblog';
$xml = simplexml_load_file($xml_file);
$xml_channel = $xml->channel->item;
for ($i=0; $i<5; $i++) {
//print_r($result);
?>

echo $xml_channel[$i]->title."
";
}
?>

There are some parameters which can customize your requirements like:

  • $xml_file = Feed Url for example i use $xml_file = 'http://feeds.feedburner.com/honeytechblog';
  • Value of i for no of links, for example i5 shows 5 links of the feed

Alternate Code

(tested on various clients blogs)


    error_reporting(0);
    $url = "http://feeds.feedburner.com/micro-news";
    $xml = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);
    echo $xml;
    if ($xml == "")
    {
    echo "Feeds are down, Try again later";
    }
    else
    {
    $blog = $xml->channel;
    for($i=0; $i<3; $i++) {
    ?>

  • }
    }
    ?>

Note

If you wants to run this php code apart from the Wordpress themes i.e in wordpress posts and pages then you need plugins like Exec-PHP. Exec-PHP will executes PHP code in posts, pages and text widgets .

This post is dedicated as an answer to amitbhawani question

Is there any Wordpress Plugin which shows 5 Recent Posts of any Feed in a Wordpress Page? Ex :Show my news blog latest posts on about page

No comments:

Related Posts Plugin for WordPress, Blogger...