Home | About | Help Center | Privacy Policy

October 10th, 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

<?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



You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackbackfrom your own site.

Subscribe to our FREE Rss Feed

Hot in Social Media


10 Best Social Media Case Studies

10 Tips To Become Social Without Using Social Media

Top 10 Tips To Enhance Personal Branding

Top 10 Expectations Of Social Media In 2010

What's Hot

Similar Interesting Posts

Tutorials On

9 Responses to “How to show RSS feeds in a Wordpress Page and Posts”

  1. @amitbhawani to show RSS feeds in a Wordpress Pages and Posts http://bit.ly/QW6Zv

  2. Did you try out this stuff on one of your post / page? Iam asking this because the code is not executing itself and i guess we need to upload some files?

  3. @Amit
    I already tested the above codes on various blogs.
    There is no need to upload any external files in wordpress engine because it already had the simplexml parsers.
    I also implement a working examples in this post.

    The code may not be executing because its a php and you haven’t yet install the Exec-PHP
    http://wordpress.org/extend/plugins/exec-php/

  4. @amitbhawani No need to upload any external files in #wordpress, already had the simplexml parsers. Rest comments >> http://bit.ly/QW6Zv

  5. Good to see that you wrote a detailed post to help one of your reader.

    Appreciate it :-)

    @djain1989
    Deepak Jain´s last blog ..Bolt Browser comes out of Beta, gets Better! My ComLuv Profile

  6. Thanks this is working, will post a tweet when the site is up with all the feeds stuff :)
    Amit Bhawani´s last blog ..WordPress Blog Backup Plugins Tools & Tutorials My ComLuv Profile

  7. Yours Welcome Amit !
    There is lot more customizations possible with xml feeds. For example we can auto fetch the images, thumbs and etc.
    Working examples are at the home page of http://www.honeytechblog.com/

  8. I’ve been looking for something like this to implement on WP blogs.

    Thanks for posting this code!
    Bryan – After5PC´s last blog ..Why Outsource? When Hiring a Web Designer or Programmer is Good For You My ComLuv Profile

Trackbacks

  1. RSS Feed Tips | Marketing A Home Business Online

Leave a Reply

CommentLuv Enabled

Additional comments powered by BackType

    Follow @honeytech On Twitter

    HP&apos;s new tagline "Let&apos;s Do Amazing" will drive a new series of TV spots and digital media ads http://bit.ly/cRrIKz
  • Subscribe For Tips


  • Top Fans Of The Day