How To Create An RSS Feed For Your Site From Scratch
Pinterest Whatsapp

How To Create An RSS Feed For Your Site From Scratch rssiconRSS 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">

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>
<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:

  <title>Entry Title</title>
  <link>Link to the entry</link>
  <pubDate>Sat, 9 Jan 2010 16:23:41 GMT</pubDate>
  <description>[CDATA[ This is the description. ]]</description>

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.

create an rss feed

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

create an rss feed

  1. Connect to the database containing all the information we require (refer above).
  2. 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)
  3. Generate the first part of the file, ie the HEADER (refer above)
  4. Step 4: For each ENTRY in ENTRIES do the following
    1. Generate an <item> tag
    2. Fill in the required tags and content (refer above)
    3. Generate the </item> tag
  5. 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.

create rss feed

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?

Enjoyed this article? Stay informed by joining our newsletter!

Enter your Email

Leave a Reply

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

  1. j6
    June 6, 2017 at 8:05 pm

    Very Concise. Worked like a charm.

  2. usama
    December 30, 2016 at 7:08 am

    very useful information

  3. Jake
    May 10, 2016 at 1:56 pm

    Supposing you have a static site, can you just manually update the feed every time you update your site?

  4. Anonymous
    October 26, 2015 at 7:04 pm

    Thank you for including the automatic rss feed generation.

  5. Serge Courrier
    March 9, 2015 at 7:13 am

    Please note that if you really want to build it from scratch, official RSS specifications are public and quite easy to read. (the specifications) (the good practices) (to make your RSS feeds discoverable)

  6. nacojohn
    February 28, 2015 at 9:28 pm

    was really wonderful. it helped though didn't explain in details

  7. Edwin
    January 12, 2010 at 8:57 pm

    I think this is good for those who are IT geeks. Though there are feedburner and google readers, the info here is still very useful. Worth reading it to gain an extra knowledge of how RSS actually works. Thanks!.

  8. imguru
    January 12, 2010 at 3:01 am

    thanks specially for including the dynamic version of rss feeds.

  9. Paul Sanduleac
    January 11, 2010 at 9:04 am

    Just use FeedBurner!

    • lingjaidee
      January 11, 2010 at 9:07 am

      i agree with u ;)

    • Mark O'Neill
      January 11, 2010 at 10:03 am

      Feedburner only works if the site has an RSS feed already. Varun is explaining how to make an RSS feed if one isn't already there.