Publishing External RSS Headlines to Your Wordpress Site

Publishing External RSS Headlines to Your Wordpress Site

January 29, 2008 ( 27 )

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-functions.php');
// here's where to insert the feed address
$rss = @fetch_rss('http://www.darrensmusicnews.com/feed/');
if ( isset($rss->items) && 0 != count($rss->items) ) {
?>
<ul>
<?php
// here's (5) where to set the number of headlines
$rss->items = array_slice($rss->items, 0, 5);
foreach ($rss->items as $item ) {
?>
<li>
<a href='<?php echo wp_filter_kses($item['link']); ?>’>
<?php echo wp_specialchars($item['title']); ?>
</a>
</li>
<?php } ?>
</ul>
<?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

Popularity: 3% [?]

27 Responses
  1. TheOzz said:

    Thanks a bunch. I just tested the code and it worked like a champ. It will need a little CSS styling, but hey, it works. I have been looking for this type of a solution and did not even think to look at the WP dashboard code. cheers!

  2. Wallace said:

    hello, Darren,
    it’s very useful for me,
    but how can i integrate 2 or more feeds?

  3. milo said:

    Looks similar to 06 Jericho One method…

  4. Thanks! I’m adding headlines to all of my sites as a result…

  5. Starling said:

    I would also like to know how this works if I want to add more feeds. The example is just one.

  6. Darren said:

    @sean: I actually thought of you when I wrote that, on account of your networked Podcast sites. Hope you find it useful.

    @milo: Thanks for the link. That ‘current_time’ bit could be really useful.

    @wallace and starling: Are you guys asking about multiple lists of unique feeds or combining multiple feeds into one? The first solution can be done by simply copying that snippet several times with several different RSS feeds, and for the second solution, if you want to pull from an aggregated feed, you can use the plugin I mentioned, or use a service like Yahoo Pipes to create your own.

  7. Starling said:

    The latter. Thanks.

  8. Have you ever tried Feevy.com?

    It’s exactly the same idea but much more easy and practical! Take a look!

    :o)

  9. edi said:

    hi darren,
    i tried your code and it works fine except that it doesn’t work if feed URL is something like : http://www.mysite.com/blog/index.php/feed/
    can you help in sorting this out? thanks if you or anyone else can help ..

  10. Darren said:

    edi: There are many ways an RSS URI is formed, but so long as you use the absolute path to the feed you’re parsing, it should work fine. Do you have a specific link to a feed that’s not working?

  11. edi said:

    thanks darren.
    the feed link i am talking about is this one : http://www.korculainfo.com/blog/index.php/feed/
    also, what i just noticed, when i tried to place code in the sidebar of the same blog (www.korculainfo.com/blog/), - the code doesn’t work - it does not display any feed from any site ( i tried with several feed urls)
    so, i guess, this must be a problem going ‘both ways’..

  12. Darren said:

    It looks like that blog doesn’t have WP installed in the root folder, but in a place called /blog/. If that’s so, you need to change the path to /rss-functions.php to wherever that file is actually located.

    Funny you linked to Korcula, I’m thinking about spending my summer there or in Zadar (or somewhere in Montenegro), if I can find a room to rent and a reliable internet connectoin.

  13. edi said:

    darren: as i have the old version of wp on running that blog, i had to change the path to /rss.php instead to /rss-function.php and it works now.

    however, feeding different site with the feed from this blog stil doesn’t work for some reason …

    re your holidays & reliable internet connection - it shoudn’t be a huge problem, as there are rooms/hotels that offer that service.
    if you decide to come in korcula , get in touch..
    thanks for your help :-)

  14. Bart said:

    Great post. I was trying to do this myself with no luck. So thanks. :)

    I did have a question though:
    Is there any way to add the date of the item?

    Thanks again.

    Bart

  15. Bart said:

    One more question:
    Is there any way to stop the feeds from caching or at least set the intervals?

    Thanks.

    Bart

  16. Darren said:

    Is there any way to add the date of the item?

    See milo’s comment further up.

    Is there any way to stop the feeds from caching or at least set the intervals?

    Hmm, I’ll look into that.

  17. If you want to display RSS feeds within your posts (so you can choose a different feed for each post, for example), there’s a new WordPress plugin that uses CaRP to do it:

    http://www.geckotribe.com/rss/carp/CaRP-WP/

    CaRP does cache the feeds, and you can set how many minutes you want it to be cached before getting refreshed (the default is 1 hour). The relevant setting is “cacheinterval”.

    CaRP is available at:

    http://www.geckotribe.com/rss/carp/ (commercial version)

    and:

    http://www.geckotribe.com/rss/rss-to-dollars/ (free version)

  18. Tapeleg said:

    This looks like something I would like to add in to a new site I want to create, combining the new membership directory approach, and allowing a feed to be displayed of the member’s last five post headlines. This would require using a custom field to publish the individual RSS address to the individual post for that member. I know how to create the custom field, but I tried a few ways to put that field into the code you have, and I could not get it to work. The code works with a static address, so I cut and pasted it in properly. What do you think? Any advice?

  19. Thanks for this bit of information, I spent an 1.5 hours tryingt o do this and every other Plugin I tried was useless!

    Thanks again!

  20. kiona said:

    Hello
    This seems to be something I’d like to have on my blog, showing in my sidebar. But I’m not very familiar with php so could you pleas tell me where to put it, as exactly as possible.

    /kiona

  21. images in rss said:

    as many have stated, this works way better than anything else i’ve seen out there.

    i’m using it to place images from a photoblog on another site, but as the script is written, the images don’t show up, just the headline. i’ve checked the rss feed, and in FeedDemon the images are definitely coming through — so what do i have to add to the above to make images come through for me on the site?

    also: is there an easy way to place the rss parsed images (thumbnails) horizontally? (trying to put them across the top of a page full of content below)

    any help from ya’ll would be appreciated.
    thanks.

  22. Darren said:

    That chunk of code I provided looks for certain elements within the XML document (like ‘title’, which is what pulls down the headline). To get images to show up, you’d need to inspect the RSS feed in question to see how it includes images, if it indeed does. You can always write little scripts that pull down feeds and customize their output.

  23. subcorpus said:

    21 already kinda tried what i’ve been trying to do …
    still … if anyone knows of a plugin which can display thubnails of images from aminus3.com … that’d be nice …
    thanks …

  24. ‘rss-functions.php’ is depreciated; use ‘rss.php’ instead

  25. Dave Mora said:

    This works like a champ but it dies over when people are using ASP for their feeds. How I hate .aspx feeds. :)

Trackbacks
  1. Seth Holladay » Links » links for 2008-01-31:

    [...] Publishing External RSS Headlines to Your Wordpress Site » Darren Hoyt Dot Com (tags: rss wordpress tutorials webdesign) [...]

  2. Looking for Wordpress module / plugin - Affiliate Marketing:

    [...] Re: Looking for Wordpress module / plugin Check this out mate Publishing External RSS Headlines to Your Wordpress Site » Darren Hoyt Dot Com __________________ Paul Wright ————– blue barracuda affiliate marketing blog | e-mail [...]

Leave a Reply