17 Aug

Displaying A RSS Feed On Your Website – Quick Guide

Updated: 10 May 2005
By Dylan Downhill

This is a quick guide to displaying an RSS feed on your website. It is not meant to be extensive, it is meant to get your feet in the door of displaying content using RSS in the quickest time possible.

Displaying RSS Data

The two main ways to display RSS data on a website is either through client side javascript or through server side scripting. The advantage of client side javascript is it offloads the processing to the site visitor, the disadvantage is the search engines don’t run client side code and so all your syndicated RSS content will not be indexed. From a search engine optimization point of view it is best to render the RSS data feed using server side scripts.

RSS Data Display Using Server Side Scripts

There are many RSS parsers available for free on the internet. The two major PHP based RSS parsers available for use are CaRP and MagpieRSS. I personally found the documentation for CaRP lacking and I felt I didn’t have enough control over the way the data was output. As this is a quick guide I will walk through using MagpieRSS to display an RSS data feed on your site.

The first thing to do is download the latest copy of MagpieRSS. When you’ve downloaded it, if you’re using WinZip you’ll hit an issue with the TAR file having an unrecognized extension. The way around this is to extract the TAR file to a temporary location and rename the extension to ‘.tar’ , then double-click on the file and WinZip will correctly recognize the TAR file and give you the ability to extract the files.

Extract the MagpieRSS code into a directory on your PC and upload to your web server (remember to keep the folder structure as you find it in the TAR file).

Make sure the page you want the feed displayed on is a PHP file (usually designated with a .php extension). Then include the following code:

<?php
require_once ‘../magpierss/rss_fetch.inc’;

$url = ‘http://www.elixirsystems.com/seo_tips/seo_tips.rss’ ;
$rss = fetch_rss($url);

echo ‘Site: ‘ , $rss->channel[‘title’], ‘ <br / >’;
if ( $rss and !$rss->ERROR) {
����foreach ($rss->items as $item ) {
��������echo ‘ <p><a href=”‘ . $item[link] . ‘”>’ . $item[title] . ‘ </a><br / >’;
��������echo ‘Publish Date: ‘ . $item[pubdate] . ‘ <br / >’;
��������echo $item[ description ] . ‘ </p>’ ;
����}
} else {
����echo ‘RSS Error: ‘ . $rss->ERROR . ‘ <br / ><br />’ ;
}
?>

The resultant page should look like the SEO Tips index page on this site.

If the file was loaded locally then your code would change slightly as follows:

<?php
require_once ‘../magpierss/rss_fetch.inc’;

$rss_file = ‘../seo_tips/seo_tips.rss’;
$rss_string = read_file($rss_file);
$rss = new MagpieRSS( $rss_string );

echo ‘Site: ‘ , $rss->channel[‘title’], ‘ <br / >’;
if ( $rss and !$rss->ERROR) {
����foreach ($rss->items as $item ) {
��������echo ‘ <p><a href=”‘ . $item[link] . ‘”>’ . $item[title] . ‘ </a><br / >’;
��������echo ‘Publish Date: ‘ . $item[pubdate] . ‘ <br / >’;
��������echo $item[ description ] . ‘ </p>’ ;
����}
} else {
����echo ‘RSS Error: ‘ . $rss->ERROR . ‘ <br / ><br />’ ;
}
?>

Note – changed lines from previous example in blue.

That’s all you need to do. If you want to change the format of the output change the foreach loop, on this site I use the full output for the index pages, and a partial output on the site map by removing the published date and the description.

RSS Data Display Using Client Side Scripts

The Jawfish application uses client side Javascript to display RSS feeds on the visitors browser. As mentioned above the data from these feed will not be indexed by the search engines and therefore your page will appear blank to the search engines. Jawfish can be downloaded here.

Syndicating Content

Our content available for syndication using RSS can be found here.

If you find these instructions helpful or if you find an error let me know.

Updates

10 May 2005 – Thanks to Gav (from Mini Tutorials) for making it XHTML compliant.


2 thoughts on “Displaying A RSS Feed On Your Website – Quick Guide

  1. You may not have noticed but it seems blank spaces are appearing as the ? character. Perhaps you have changed the content type of your page without realising?

    I am using Google Chrome 5 on Mac.

Leave a Reply

Your email address will not be published. Required fields are marked *