Thursday, March 22, 2007
If you've used the Internet for any length of time, you're bound to have come across the term 'RSS' which stands for Rich Site Summary or Really Simple Syndication. RSS feeds are basically a simply way of letting other people subscribe to your content or display it on their website. You can even use it to show your latest blog posts on another part of your own website, or to promote one of your websites on another.
If you use any blogging platform such as Blogger, Wordpress etc...then RSS feeds are automatically generated and if you visit a site with a feed you'll probably see a little blue or orange button somewhere that says 'RSS' or 'XML'.
There are plenty of ways to display an RSS feed on your site - just search Google. However, most of these use JavaScript and you might not want to use this on your site.
Here's how to do it with Open Source software using PHP:
- Download MagPieRSS from Sourceforge.
- Unzip the files - there's lots of useful documentation but you only really need five files:
- rss_cache.inc
- rss_fetch.inc
- rss_parse.inc
- rss_utils.inc
- extlib/Snoopy.class
- Upload these five files to your website into a directory called 'rss'
- I like to create files on a modular basis, so that if I create the RSS feed file once, I can then re-use the code wherever I like on my site. Some people like to create the feed instructions exactly where it will appear in the site. This is up to you. These instructions are for the modular version.
- Create a new file called rss.inc.php - go to notepad and save the file as "rss.inc.php" including the quotes where it asks for the filename.
- In this file put the following code:

EDIT: in the above code
foreach ($rss->items as $item)
should read
foreach ($items as $item)
- Taking it step by step - in the first two lines (after the PHP opening tag) you are telling the script exactly where to find the files it needs. In the third line, you put in the RSS feed you want to display. The fourth line limits the number of items to 5 (want to show 10? Just change the 5 to a 10!). The following line says that the results are going to be shown as an unordered list. Then the for 'loop' shows the RSS item for entries 1 t0 5 in the feed. The last line closes off the unordered list.
- In the loop, I've specified that the list item should consist of the RSS item title ($title), hyperlinked to the item itself ($link), and that the description ($desc) should follow. You can display the information in any way that you wish, using the three $link, $title and $desc variables.
- What if you don't want to limit the number of items? Just take out the line

- Upload rss.inc.php to your rss feed folder
- To integrate the feed on your website, decide where on your PHP page you want the feed to go.
- Insert the following code:

...And that should be it! Obviously this is just a very brief guide to outline the basics and I can't guarantee that this will work on all hosting packages. RSS feeds can contain a lot more information than just the title, link and description that I've outlined above so for more detailed information see
MagpieRSS.
For "The Anatomy of an RSS feed" - see
http://www.webreference.com/authoring/languages/xml/rss/feeds/ and if you're wanting to create a feed 'on the fly' with PHP and MySQL see
http://www.webreference.com/authoring/languages/xml/rss/custom_feeds/Labels: programming, rss
