Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I am running a static PHP website for the past 3 months. It's not a CMS but just simple PHP files (no database) in to which I add content. I am struggling to manually create RSS feeds as it is very time consuming. Can someone suggest me ways to save time creating RSS feeds? I am also looking to automate the process of RSS feed creation, maybe using variables? Please suggest.

share|improve this question
    
If you choose to create a static website (even though you're already using PHP), then you're going to have to create your RSS feeds by hand. That's why no one maintains static sites anymore. It's very easy to generate RSS or Atom feeds automatically when you have a dynamic website. –  Lèse majesté Dec 21 '11 at 3:59
    
Can't you find a php library that helps you in creating a RSS feed? –  ZippyV Dec 21 '11 at 8:33
    
@ZippyV: That wouldn't help if his website is static and he's just using php like SSI to include header/footer/navigation on individually created pages. The best he could do is manually maintain an RSS file that he adds to whenever he adds new content. –  Lèse majesté Dec 21 '11 at 10:41
    
This question has some PHP libraries in the answers that generate feeds: stackoverflow.com/questions/1888069/… –  paulmorriss Dec 21 '11 at 12:49
add comment

2 Answers

up vote 3 down vote accepted

As alluded to in the comments, you'll need a database holding your content to be able to automate your feed. We don't know from your question how comfortable with PHP you are or if you have any database experience, but this would almost certainly speed up other things in your site too - such as being able to serve each of your 'content' pages from one dynamic script, rather than trying to maintain several static pages.

I'm going to assume for a minute that you have MySQL and you know how to set up a table. Do that, and make sure your table (which i'll call "my_content" looks something like this:

item_id (int 6, auto increment)

item_title (char 255)

item_description (text)

In PHP, connect to your database - again, this is extremely simplified, you'll need to investigate further to add in some error checking and all that, but its just to point you in the right direction and show you how simple it can be to get started. (Also, MySQLi is the modern thing, but lets avoid OO for now..)

<?php
//Connect to a database server and find your database
mysql_connect($host,$user,$password);
mysql_select_db($db);

//Select the content for your feed
$SQL = "SELECT * FROM my_content ORDER BY item_id";
$QRY = mysql_query($SQL);

//Set up the XML header
$xml  = '<?xml version="1.0" encoding="UTF-8" ?>';
$xml .= '  <rss version="2.0">';
$xml .= "    <channel>"; 

//Loop through the result set created in $QRY and add it into $xml
while ($ROW = mysql_fetch_assoc($QRY)) {    
  $xml .= "<item>";    
  $xml .= "  <title>".$ROW['item_title']."</title>";    
  $xml .= "  <description>".$ROW['item_description']."</description>";    
  $xml .= "  <link>http://www.mysite.com/content.php?id=".$ROW['item_id']."</link>";    
  $xml .= "</item>";        
}

//Add the XML footer
$xml .= "    </channel>";
$xml .= "  </rss>";

//Write the whole lot to a file.
file_put_contents("rss.xml",$xml);
?>

There you go. That's how easy it can be, although an RSS feed probably needs more information, I think thats about the bare minimum to create something that's valid. While you're welcome to copy/paste this bit of code - it won't win any programming awards, i've just tried to keep it extremely simple to give you the basic idea of how it works.

If you deploy anything on a real website, depending on many factors (not least who is using it, how they are putting content into the database, etc) you will want to work on things like error checking and data validation.

Hope it helps.

share|improve this answer
    
I have numerous files and I am an average PHP coder. So I cannot convert the site into a website. I am using PHP only to include the header, footer etc. –  Sam Dec 21 '11 at 14:23
    
Unfortunately, it looks like you're stuck having to manage the files manually. Alternatively either hire a developer or implement an off-the-shelf CMS package and convert your static website into a dynamic one so that you can automate RSS feeds and other features. If you plan to run a large site, database driven is really the only option - it won't take long to become unmanageable if its all static. –  Codecraft Dec 21 '11 at 15:17
    
Although, your code did not help, you was correct. I am now looking to move to WordPress. –  Sam Dec 25 '11 at 18:15
add comment

Yes it is possible to create an rss.xml feed automatically

This website is a static website and apparently it has an auto generated rss.xml

http://whatanswered.com/rss.xml

Validate the RSS feed

http://appc.w3.org/check.cgi?url=http%3A//whatanswered.com/rss.xml

Why don't you contact them via their website and ask them?

share|improve this answer
1  
How can you tell that the RSS feed is generated automatically? –  Lèse majesté Jan 27 '13 at 5:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.