Display WordPress Feeds On Your Site With SimplePie
You can display your latest WordPress posts anywhere on your site by using an RSS reader called SimplePie and a few lines of code. SimplePie is a fast and efficient RSS reader, and it will also cache feeds to reduce the amount of processing time taken.
Download simple pie from the website and upload the simplepie.inc file to your web server. Next include the following section of code anywhere on your site that you want to display the latest post on.
<?php
require_once('simplepie.inc');
$feed = new SimplePie();
$feed->set_feed_url('http://www.example.com/feed');
$feed->init();
echo '<ul>';
// Limit the items to be shown
$i = 1;
foreach($feed->get_items() as $item){
if($i<3){
echo '<li><a href="'.$item->get_permalink().'">'.$item->get_title().'</a><br />'. "\n";
echo substr($item->get_description(),0,180).'...</li>'."\n";
$i++;
}
}
echo '</ul>';
?>
You can also pull out categories by setting the feed URL to something like this.
http://www.example.co.uk/category/example/feed
This will allow you to display a page will posts from different categories.
Of course you can use this technique on any RSS generating blog platform, it doesn’t have to be WordPress, but it is much better than trying to figure out database connections and the like.
Information, services, and products:Does your shop need Display Cabinets ? then come to us.
www.justdisplays.co.uk
Baby Cradles
Display cases
You can simplify even further by passing the $start and $length values to get_items() in the foreach loop:
foreach($feed->get_items(0,3) as $item) { … }
why it is not work for my blog, i already follow your instruction but not work, please help me.
Just spent half an hour looking for code to do this as the site I was working on clashed with WordPress, so couldn’t include the WP-header. As ever Phil, you were a lifesaver.
But you’ve left JS now, so will you actually get this? Who knows, who cares. Thanks anyway!
can i do this for 20 blogs at the same time???
the same is with me. tested simplepie with a few feeds and works but not with mine
. I’m using wordpress feeds.
I really like this blog good job.