Code to Display RSS Feeds
Here is some simple PHP code to display RSS feed data from external sites on your web page.
Using powerful features of the PHP scripting language, this is a surprisingly simple task to achieve. But make sure you have permission to use any feeds in this way.
My example uses the BBC News feed which is free to use as long as proper attribution is included in your page e.g. “News from the BBC”.
<?php
$rss = fetch_rss("http://newsrss.bbc.co.uk/rss/newsplayer_world_edition/uk/rss.xml");
$rss = fetch_rss("http://newsrss.bbc.co.uk/rss/newsplayer_world_edition/uk/rss.xml");
echo "<h2>", $rss->channel[‘title’], "</h2>";
foreach ($rss->items as $item ) {
$title = $item[title];
$description = $item[description];
$url = $item[link];
}
?>




Since “fetch_rss” isn’t a built-in PHP function, there must be something missing here — an “include” or “require” to load some script that provides that function. Is this using Magpie or something?
Does the script you’re using provide caching of the RSS feed? If not, then your server will be fetching the feed every single time someone loads the page it’s displayed on. This will slow down your site, increase your bandwidth usage, and possibly get your server’s IP address blocked by the site that publishes the feed. A script like CaRP — http://www.geckotribe.com/rss/carp/ — will keep a cached copy of the feed on your server and update it periodically.
Finally, why are you routing all of the clicks through your wp-admin directory?
Comment by Antone Roundy — January 12, 2008 @ 9:44 am
This was a pretty dumb post I did.
The “fetch_rss” is a Magpie function http://magpierss.sourceforge.net and needs to be included with the PHP code:
require_once ‘rss_fetch.inc’;
“Finally, why are you routing all of the clicks through your wp-admin directory?” I think it was some effect of WordPress altering what I entered into the post. I deleted that link.
Thanks for pointing out my mistakes!
Caching is a good idea, thanks for the tip.
Comment by Andy — January 12, 2008 @ 10:20 am