31 December 2010

How to create rss feed for static website

What is RSS?

RSS is most commonly abbreviated as Really Simple Syndication. It is an xml document used to provide the summary of the site contents. RSS is used to send users notification about what’s new on the site since they have last visited it.

Syntax

For creating a RSS feed for your site you must be familiar with xml tags. Basically rss feed comprises of two parts first part is about your site and second part is about your content.

You have to place the following code on the beginning of your xml file. This will initialize the xml document as rss feed.

< ?xml version="1.0" ? >
< rss version="2.0">
< channel >

Then comes the first part of your rss feed which is about your site information. In this part you need to define information about your site. Place the following code immediately after the previous code in your xml file:

< title>Skills 2 Earn< /title>
< description>Knowledge for all< /description>
< link>http://skills2earn.com< /link>

In the above code “< title>” tag is used for setting the title of your site, “< description>” tag for description and “< link>” tag for the link of your site.

Now comes the second the most important part of your rss feed, in this part you need to define the information about your content. For this purpose “< item >” tags are used. If you want to put four topics in your feed then you need to use four “< item>” tags. Following is an example code to let you know how these item tags can be used:

< item>
< title>title of your topic< /title>
< description>description of your topic< /description>
< link>http://www.example.com< /link>
< /item>

In the above code “< title>” tag is used for setting the title of your topic, “< description>” tag for description and “< link>” tag for the link of your topic.

In the end you need to close all open tags. As I am doing in the code below:

< /channel>
< /rss>

Now in the last, rss files are like other xml files and they will be treated as text, so if you run your xml file on your local server or web server then the contents of the file will be displayed on the screen. So you need to tell apache to treat these xml files as php files. This can be done by adding following code in the .htaccess file:

AddType application/x-httpd-php .xml

That’s it guys, you have done it, you have created an rss feed for your website.

Complete Code

Complete code is mentioned below. You need to safe it in an xml file and you can name it as “rss.xml”.


< ?xml version="1.0" ? >
< rss version="2.0">
< channel>
< title>Skills 2 Earn< /title>
< description>Knowledge for all< /description>
< link>http://skills2earn.com< /link>
< item>
< title>title of your topic< /title>
< description>description of your topic< /description>
< link>http://www.example.com< /link>
< /item>
< item>
< title>title of your topic< /title>
< description>description of your topic< /description>
< link>http://www.example.com< /link>
< /item>
< /channel>
< /rss>


For any problems or queries, you may have, feel free to comment on this post. I would love to resolve your problems.

No comments: