RSS feeds for your content are very important these days. A large number of people stay updated using RSS readers which pull in updates from the sites subscribed. In addition, RSS feeds can be used in a number of ways to promote your content using social media.
An RSS feed for your site is essentially an XML file. You must adhere to a specific format for the XML file (as we shall see) for it to be identified as an RSS feed.
Let’s first have a look at how to create an RSS feed for your site from scratch.
All you have to do is to specify your information for all the necessary tags. You can use any text editor. Notepad would work fine but have a look at Notepad++. Let’s see what each of them mean. To create an RSS feed, you start off the RSS file as follows:
<?xml version="1.0" encoding="utf-8"?> <rss version="2.0"> <channel>
The first two lines specify the XML and RSS version as you can see. The third line opens a “channel” tag. This is what would contain all the information for your channel or website. Add these three lines as they are.
<title>MakeUseOf RSS Feed</title> <link>//www.makeuseof.com/</link> <description>Cool Websites, Software and Internet Tips</description>
Those few lines specify information about your RSS feed and your website. The title tag houses any title that you would like to give to your RSS feed, link tag points to your website, description tag contains a brief introduction about the RSS feed or the website. Whatever is inside your file now, lets call it the HEADER
Next up we have the actual content of the RSS feed that will be displayed as distinct entries when viewed using a feed reader. Each entry is contained within a pair of <item></item> and must have the following content at least:
<item> <title>Entry Title</title> <link>Link to the entry</link> <guid>http://example.com/item/123</guid> <pubDate>Sat, 9 Jan 2010 16:23:41 GMT</pubDate> <description>[CDATA[ This is the description. ]]</description> </item>
Again the title tag would refer to the heading or your content, link is the complete web address at which the entry can be reached on your website, guid is a unique identifier for the entry. Since all of your entries would be located at a different URL, you can use the link as the guid (if of course no two entries would point to the same URL in your setup). pubDate houses the date on which the entry was published.
The data has a specific format, refer above, the time must be in GMT, you can also refer to RFC 822 section 5 for more details on other date-time specification format. Finally the description tag houses the actual content or description of the entry. Remember the above would be repeated for every entry on your website. For example if you have a blog with 5 articles, a complete RSS feed should have 5 item tags to house 5 entries.
Close off the open channel and rss tags and save the file. Upload it to the appropriate location on your web server (the site root would work fine) and you have an RSS file at your disposal.
Now if you sit down and think about it, you would at once realize that the file you just created is static, meaning that the entries that you wrote inside the item tags would remain the same and wouldn’t change to reflect the most recent content of your website. So before we wrap things up, we have a couple of issues that need to be addressed.
Make the feed dynamic
Now this would require a fair bit of programming. If you are not confident with your programming skills, I suggest you’d be better off using a CMS like Joomla, Drupal or still better – WordPress (if that suits you). CMS’s have a number of plug-ins for RSS feeds and most of them would offer RSS functionality out of the box. However, since you are reading this, I assume you are brewing your own solution and so let’s get coding.
You can use the same programming language that you have used to program your site. All we are going to do is to fetch the entries from the database and insert them into appropriate tags. I can only briefly outline the steps because the actual code would vary according to the programming language you are using
- Connect to the database containing all the information we require (refer above).
- Fetch all the ENTRIES that you want to add to the RSS feed. Usually it is the 10 most recent ones (so you can use “ORDER BY <the date column name here> DESC” in your SQL query)
- Generate the first part of the file, ie the HEADER (refer above)
- Step 4: For each ENTRY in ENTRIES do the following
- Generate an <item> tag
- Fill in the required tags and content (refer above)
- Generate the </item> tag
- Generate the FOOTER to close off the file.
Make the feed discoverable
Another thing you need to keep in mind is that feed readers should be able to identify the generated feed as an RSS feed. There are plenty of ways to do this:
- You can create an XML file as the RSS file and open it up, manually add items everytime a new entry is published or whenever the feed should be updated.
- Or if you using a script to create the RSS feed each time it is requested, you could send a Content-Type: application/xml header before any other information.
- You could save the script as an XML file and have your web server software treat it as a scripting file. Example, by adding:
AddType application/x-httpd-php .xml
in .htaccess would make Apache treat XML files as PHP files.
Ideally, Firefox should recognize the RSS feed when the feed’s URL is entered into the address field as opposed to showing the contents of the script.
This means that Firefox detects that the file is an RSS XML file. You can then head over to services like Feedburner with your feed URL to get all kinds of analytics and other options to play along with.
Did this tutorial help you create your own RSS feed?