I wouldn’t advise republishing content from any old RSS feed, but sometimes there’s a reason.
Let’s say in addition to DarrenHoyt.com, I also owned DarrensMusicNews.com, and I wanted to display those headlines in this blog’s sidebar. There are plugins to accomplish this, and sweet RSS/XML parsers like SimplePie, but Wordpress already comes with a function to handle it — this can be seen on your WP dashboard page where headlines are pulled from the Planet Wordpress feed.
That dashboard code lives in /wp-admin/index-extra.php, which is where I took fragments and rewrote it to a simpler snippet:
<?php
require_once (ABSPATH . WPINC . '/rss.php');
// insert the feed URL here
$rss = @fetch_rss('http://www.darrensmusicnews.com/feed/');
if ( isset($rss->items) && 0 != count($rss->items) ) {
?>
-
<?php
// set the number of items from the feed to display (10)
$rss->items = array_slice($rss->items, 0, 10);
foreach ($rss->items as $item ) {
?>
- '> <?php echo wp_specialchars($item['title']); ?> <?php } ?>
Give it a try. The code is mainly valuable for interlinking multiple sites you may own (check out the “Recently on the GigaOM Network” module in the footer of GigaOm.com. That can also be accomplished with the BlogNetworking plugin).
If you do decide to parse/publish someone else’s blog feed, it’s best to get permission first and give proper credit, and don’t just do it for crummy advertising dollars :P
Follow me on Twitter
4:33 pm
Very useful information, thanks!
12:34 pm
I’m a little late to the party since you published this in 2008, but it seems to suit my needs for a quick and dirty task I am trying to accomplish. I normally use Carp, but not having to install that and just use this instead made it much more simple. Many thanks!