Make your own RSS Feeds

Ralph van den Berg's picture

If you’re making your own website, and you long for that little orange icon to light up when visitors come to your site, the way it lights up on other websites, ones that have RSS feeds, then search no more, because I’ll show you how.

It’s more simple than you would expect. You just need to become familiar with XML, which is (trust me) a lot simpler than HTML or PHP. For a successful RSS feed, you really only need to know a handful or two of tags. If you’re already familiar with HTML, then it’s easy to understand. Every tag in XML opens and closes in the same way: <opentag> </closetag> and you just stick content in the middle.

Lets start our XML file by declaring it so:
<?xml version="1.0" encoding="utf-8"?>
Contrary with what I said before, this line you don’t need a closing tag for, but it’s the only exception as far as we’re concerned now.

Next, we’ll let readers know that this is no ordinary XML file, NO, this is a RSS feed:
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
This line you will need to close at the end of your file:
</rss>
And we’ll let the readers know it’s a channel like this:
<channel> </channel>
Stick these channel tags in our <rss> tags, and the rest of our content and tags will be within those channel tags.

Let’s continue by describing our channel before we add items to it. We’ll need a title, a description, and a link would be nice. Check out how simple that is:
<title>Our New RSS Feed</title>
<link>http://ralphvandenberg.com</link>
<description>The greatest website in the world, come check it out!</description>

We can add more tags to further define our channel, but they are optional. For example, you can add:
<language>en-us</language>
<lastBuildDate>Tue, 08 Jul 2008 17:49:20 +1200</lastBuildDate>

Make sure you follow the correct format for the dates.

Now our channel is defined, we can start putting items in. This won’t get difficult, it’s been easy so far, and it’ll stay easy!
<item>
<title>Web Projects</title>
<link>http://ralphvandenberg.com/webprojects</link>
<description>See more information about web projects by Ralph</description>
</item>

I feel like I’ll sound dumb if I start explaining this, because if there was anything in the world that’s self-explanatory, then it’s this.

You can keep adding more items; just put them in one after the other. You can also add more optional detail to these items, such as author (must include email address), guid (an absolute unique identifier, I just use my link again), and pubDate (must be in the correct time/date format).

Let’s say we have about 10 items now in our XML file. Let’s save it as rss.xml in the root directory of our website. Now load your page, and voila, still the orange RSS icon won’t light up! Don’t worry, we just need to include one more line in the <head> section of your webpage. Just add this line:
<link rel="alternate" type="application/rss+xml" href="rss.xml" title="My Own RSS Feed">
Load up your website again and now is it working? You can even put a link on your website somewhere to encourage people to subscribe to your RSS feed like this:
<a type="application/rss+xml" href="rss.xml">Subscribe to my Feed!</a>

Here’s an overview of what we’ve done:
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Our New RSS Feed</title>
<link>http://ralphvandenberg.com</link>
<description>The greatest website in the world, come check it out!</description>
<language>en-us</language>
<lastBuildDate>Tue, 08 Jul 2008 17:49:20 +1200</lastBuildDate>
<item>
<title>Web Projects</title>
<link>http://ralphvandenberg.com/webprojects</link>
<description>See more information about web projects by Ralph</description>
</item>
<item>
<title>About me</title>
<link>http://ralphvandenberg.com/aboutme</link>
<author>no-reply@ralphvandenberg.com (Ralph van den Berg)</author>
<description>Find out more about our favorite superhero: Ralph</description>
</item>
</channel>
</rss>

If you want your website to automatically generate XML files whenever new content is submitted, then take a sneak peak at the article Pretty URLs (how to), the part about PHP making new files for you to be specific! It’s not hard at all!

Good luck making your own feeds!

Ralph van den Berg
visit RalphvandenBerg.com
Subscribe to my Feed


Comments

ken's picture

Thanks Ralph!

Nice Post! I'll be back if I need to set RSS up...!

Chiang Mai Plan
Thai Tan Thai
Laos Plan
Thai Hotel Plan

Ralph van den Berg's picture

RSS Feed Reader

Turns out things are getting easier. I have the feeling that PHP has a XML document creator built in. I'm not sure, but I do know that it can easily do the reading. No need to download other people's RSS readers if you want live content on your site. Just build your own RSS feed reader! Or do what I did, and copy most of the code from W3C (I think it was from there, I can't find it in my browser's history). The nice part is that it's coded with PHP, which means you have real content on your site- updated new content. Search engines love that!

You can also make it more dynamic, where AJAX runs the get-me-my-rss.php and displays it on your page asynchronously, but the search engine spiders are not good at async requests.

In summary, it's easier than other people make it sound, as usual, and give it a go!

---Ralph van den Berg
visit RalphvandenBerg.com

Ralph van den Berg's picture

Find the code here:

http://www.w3schools.com/php/php_ajax_rss_reader.asp

I did a quick search, here's the link to all the code you'll need. It's easy to understand, works simple, easy as hell to modify, and just to let you know; with a few minor changes the getrss.php file, you can run it alone (without calling it through AJAX).

---Ralph van den Berg
visit RalphvandenBerg.com