logo
Page Affairs

Editing and Web Design

Create Your Own Simple RSS Feed

Note: posted May 2009.

RSS once stood for Rich Site Summary, but now—in its latest incarnation—it stands for Really Simple Syndication. Personally, I prefer the old definition. But still, RSS is very simple, as I’d like to demonstrate here.

(Please note that this is not an expert article, but rather notes by a NOOB for other NOOBs. If you know how this post could be improved, please have your say at the bottom of the page.)

An RSS ‘feed’ is a simple document added to a website that lists the site’s most recent updates. For example, if a blog entry is added to a site, normally a short summary of it (or the entire entry) will appear at the top of the site’s RSS updates (or list of most recent entries).

When a site offers an RSS feed, you will see an RSS icon somewhere near the top of your browser window. In Firefox, Safari and Opera, it appears at the right-hand end of the address bar, and in Internet Explorer you see it just under the address bar.

Typically, blogging software (like WordPress) and content management systems come with built-in RSS feeds that update automatically, thanks to a lot of PHP (or perhaps some other kind of) code.

But what if you have a simple site without either of these, and you would like to provide an RSS feed? Knowing nothing about RSS myself, I decided to have a go at creating my own simple RSS feed. It turned out to be very simple; and if you follow the tips I give below, you, too, will have a simple RSS feed set up on your site in minutes.

There are several different kinds of RSS feed, such as RSS .92, RSS 2.0 and Atom 0.1. Most people seem to use RSS 2.0, so I’ll show you how to set that up first, and at the end mention the other two just for completeness.

Step 1

All you really need to do is add a simple file somewhere to your site with a .xml extension. I created a folder (or ‘directory’ in web speak) called rss, and inside that folder I created a file called rss2.xml.

Into rss2.xml, place the following code:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
>

<channel>
<title>My Site Name</title>
<link>http://www.mydomain.com/</link>
<atom:link href="http://www.mydomain.com/rss/rss2.xml" rel="self" type="application/rss+xml" />
<description>My RSS Feed Subtitle</description>
<language>en</language>

  <item>
<title>A Post Title</title>
<guid isPermaLink="true">http://www.mydomain.com/file-location/</guid>
<link>http://www.mydomain.com/page-location/</link>
<pubDate>Wed, 30 Apr 2009 23:00:00 +1100</pubDate>
<description><![CDATA[ <p>This is a brief summary of the post, so tempting that no one will be able to resist clicking through.</p> ]]></description>
  </item>

</channel>
</rss>

I got this basic code by viewing source code (View > Page Source) while looking at people’s RSS feeds in FireFox. The code above is a stripped down version, with just the main essentials (along with a few optional bits, such as <pubDate>).

This is the basic code you need for your RSS 2.0 feed. You should modify the details under <channel>, as this information identifies your RSS feed. For example, my own RSS feed reads:

<title>Page Affairs</title>
<link>http://www.pageaffairs.com/</link>
<atom:link href="http://www.pageaffairs.com/rss/rss2.xml" rel="self" type="application/rss+xml" />
<description>Tips on Words and Web Design</description>
<language>en</language>

The next bit (between the two <item> tags) is the code for an individual news item. Each time you add an item to your feed, you just copy this code (including the <item> tags) and paste it above the other item entries, then change the details as appropriate.

For example, an entry for the post you are now reading might look like this:

<item>
<title>Create Your Own RSS Feed!</title>
<guid isPermaLink="true">http://www.pageaffairs.com/web/rss/create-a-simple-rss-feed/</guid>
<link>http://www.pageaffairs.com/web/rss/create-a-simple-rss-feed/</link>
<pubDate>Mon, 04 May 2009 10:00:00 +1100</pubDate>
<description><![CDATA[ <p>Read this article to find out how to create your very own RSS feed!</p> ]]></description>
</item>

Once you have pasted your RSS code into a .xml file, enter in your site details as shown above, create your first <item> (even if it’s just a pretend one), and then upload the rss folder and .xml file to your website.

To make your new RSS feed accessible, you will then need to take the following step:

Step 2

On the home page of your site, add this link inside the <head> section:

<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://www.mysite.com/rss/rss2.xml" /> 

Upload the updated version of the home page, and view it in your browser (and, of course, make sure to refresh the browser if the page was already open).

Hey presto! With any luck, you should see the RSS icon near the top right of the page.

If you click on the RSS icon, your browser will open the RSS feed as a new web page. At this point, you will only see one item displayed, but an RSS feed will normally have a list of your latest updates, so you can go back to your .xml file and add more items when you are ready. Make sure to place the newest items above the older items, as readers expect the latest entries to show first.

Once you’ve saved this file and uploaded the changes, refresh your home page and click the RSS icon again; and, if the gods aren’t agin’ you, you’ll see new updates listed in the RSS feed. (See the Final Notes below for troubleshooting.)

And that’s it, folks. It’s that simple. Each time you make a change to your site, just add another <item>.

But Wait…

I wasn’t satisfied to leave it there, because at this stage, people can only open your RSS feed from the home page. I wanted the RSS feed to appear in the address bar of every page. Easy. Just add the header link shown above to the header section of every page. (Ideally, all this code—such as CSS and RSS links—should be stored in one place and linked via a PHP include.)

But I still wasn’t satisfied, because I would like a link to the RSS feed to appear on my site’s pages as well, where I can advertise it and encourage people to sign up.

Again, easily done. Wherever you want a link to appear, just do something like this:

<p>LINK TO MY <a rel="alternate" type="application/rss+xml"
href="http://www.mysite.com/rss/rss2.php">RSS FEED!</a>.</p> 

Clicking this link will have the same effect as clicking the RSS icon at the top of the browser.

RSS .92 and Atom

The setup for the older RSS .92 news feed and Atom 1.0 is pretty much the same.

For RSS .92, start with this code:

<?xml version="1.0" encoding="UTF-8"?>

<rss version="0.92">

<channel>
<title>My Site Name</title>
<link>http://www.mydomain.com/</link>
<description>My RSS Feed Subtitle</description>
<docs>http://backend.userland.com/rss092</docs>
<language>en</language>

<item>
  <title>A Post Title</title>
  <description><![CDATA[ <p>This is a brief summary of the post, so tempting that no one will be able to resist clicking through.</p> ]]></description>
  <link>http://www.mydomain.com/page-location/</link>
</item>

</channel>
</rss>

Paste this into a new file called rss.xml, place it in the same rss folder, and upload. Also add the following code to the header section of your site:

<link rel="alternate" type="text/xml" title="RSS .92" href="http://www.mydomain.com/rss/rss.xml" />

For Atom, start with this code:

<?xml version="1.0" encoding="UTF-8"?>

<feed
xmlns="http://www.w3.org/2005/Atom"
xmlns:thr="http://purl.org/syndication/thread/1.0"
xml:lang="en"
>
<title type="text">My Site Name</title>
<subtitle type="text">My RSS Feed Subtitle</subtitle>
<updated>2009-03-03T10:00:00+11:00</updated>
<link rel="alternate" type="text/html" href="http://www.mydomain.com/" />
<id>http://www.mydomain.com/rss/atom.xml</id>
<link rel="self" type="application/atom+xml" href="http://www.mydomain.com/rss/atom.xml" />

<entry>
  <title type="html">A Post Title</title>
  <link rel="alternate" type="text/html" href="http://www.mydomain.com/page-location/" />
  <id>http://www.mydomain.com/page-location/</id>
  <updated>2009-04-30T23:00:00+10:00</updated>
  <published>2009-04-30T23:00:00+10:00</published>
  <author><name>Author Name</name></author>
  <summary type="html"><![CDATA[ <p>This is a brief summary of the post, so tempting that no one will be able to resist clicking through.</p> ]]></summary>
</entry>

</feed>

Paste this into a new file called atom.xml, place it in the same rss folder, and upload. Also add the following code to the header section of your site:

<link rel="alternate" type="application/atom+xml" title="Atom 1.0" href="http://www.mydomain.com/rss/atom.xml" />

Final Notes

Adding Tags

You can add HTML tags (such as <p> and <a>) in your feeds, but you must make sure they are wrapped within CDATA tags to prevent an error occurring:

<![CDATA[ <p>Text here</p> ]]>

You could still use your HTML tags without the CDATA code by using entity references to create them. For example, you could either write:

<description><![CDATA[ <p>Text here</p> ]]></description>

or

<description>&lt;p&gt;Text here&lt;p&gt;</description>

CDATA tags tell the browser that what’s inside should not be interpreted as XML markup.

Dates and other Optional Bits

You can just cut out the <pubDate> code if you can’t be bothered with it, but if you stick with it, be aware that the format is very strict. It must be in this format:

Wed, 30 Apr 2009 23:00:00 +1100

Days must have only three letters (Mon, Tue, Wed, Thu etc.), don’t add things like ‘th’ after 30, and keep the month name also to three letters (Jan, Feb, Mar etc.). The +1100 indicates that Melbourne time (where I come from) is 11 hours ahead of GMT. Change to suit your circumstances. (Of course, if you are behind GMT, use a minus rather than a plus sign.)

Some other parts of the RSS code are optional, such as the <guid isPermaLink=“true”> bit, and, as mentioned, the CDATA code can be removed.

Validation

It’s a good idea to check for bugs and potential problems by validating your RSS feeds. Go to the Feed Validator site.

Troubleshooting

RSS is written in XML, which, unlike HTML, is totally unforgiving when it comes to errors. If you have one character out of place (like a missing closing tag, or even the last > of a tag) you may get a white screen of death, or at least a blank gap in your message. So be careful. If your entries are not displaying properly, go over your code carefully. Also, if you are adding characters other than standard letters and numerals (such as &), use entity references (&amp;) or character references (&#38;).

I also find that some browsers get a little huffy if you add links within the <description> section, but maybe that’s just me. (Don’t say I didn’t warn you. Maybe someone can offer clarification on this.)

Acknowledgements & Links

Legacy Comments

Ruth — March 09, 2014

Thank you for this really clear explanation! I have always wondered how it happened and you have covered this thoroughly as well as how to do it yourself. Excellent! Off to try it now …

Ralph Mason — March 09, 2014

That’s great, Ruth. Glad you found it useful. It would be nice to know how you go with it. smile

richard — March 31, 2014

Hi

Is there any way to do this for a website that is currently not uploaded online?

Thanks

Ralph Mason — March 31, 2014

Hi Richard. You can certainly set this up offline ready for use, but it wouldn’t be much use until uploaded, as no one but you would see it. What are you trying to do?

© Page Affairs, 2008–2024