This is a handy bit of code that can be used to list recent posts from your favorite blog/RSS feed in your WordPress theme.
For example, let’s say you love ChurchMag so much, you decide to list our five most recent posts in your sidebar.
Here’s the code:
[cc lang=”php”] include_once(ABSPATH.WPINC.’/feed.php’);
$feed = fetch_feed(‘http://feeds2.feedburner.com/churchmag’);
$limit = $feed->get_item_quantity(5); // specify number of items
$items = $feed->get_items(0, $limit); // create an array of items
}
if ($limit == 0) echo ‘
‘;
else foreach ($items as $item) : ?>
get_title(); ?>
[…]
[/cc]
How awesome are you?
This could be used in a lot of different ways:
- List the most recent post(s) from your favorite blogs.
- List recent blog posts from your other blog.
- Drop a RSS news feed in your theme.
What other uses would be awesome?
[via WordPress Code Snippets]
Joe says
Can this code be put in a text widget, or does the sidebar.php need to be edited directly?
Eric Dye says
Should be sidebar.php