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

<?php
$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);
?>
<div>
<a href="<?php echo $xml_channel[$i]->link; ?>">
<?php
echo $xml_channel[$i]->title."</a></div>";
}
?>

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 i<5 shows 5 links of the feed

Alternate Code

(tested on various clients blogs)

<ul>
  <?php
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++) {
?>
 <li><a href="<?php echo $blog->item[$i]->link; ?>"><?php echo $blog->item[$i]->title; ?></a> </li>
  <?php
}
}
?>
</ul>

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


Comments

16 responses to “How to show RSS feeds in a WordPress Page and Posts”