RSS Feed


This will be a continuation of: https://rmb-scripting.com/tutorials.php?tutorial&tid=21

Now first off, create a new file and anme it rss.php or what ever you want.

When you are finished open it up and type up something like the following:
PHP Code
  1. <?php
  2. header('Content-type: text/xml'); //change file type to XML
  3. include("db.php"); //get config
  4. ?>
  5. <rss version="2.0">
  6. <channel>
  7. <title>Feed Name</title>
  8. <description>Feed Descriptiondescription>
  9. <link>https://yoursite.com</link>
  10. <?
  11. $result = mysql_query("SELECT * FROM entries ORDER BY id DESC"); //get the information
  12. while($row = mysql_fetch_assoc($result)){ //repeat the info
  13. ?>
  14. <item>
  15. <title><?=$row['title']; //echo the title
  16. ?></title>
  17. <description><?=$row[short]; //echo the content
  18. ?></description>
  19. <author>SiteName submissions@yoursite.com</author>
  20. <link>https://yoursite.com/index.php?id=<?=$row['id']; //another link to the article
  21. ?></link>
  22. <guid>https://yoursite.com/#<?=$row[id];// Quick Link
  23. ?></guid>
  24. </item>
  25. <?
  26. } //end the while
  27. ?>
  28. </channel>
  29. </rss>


Be sure to change all your variables and upon checking it with W3C Feed Validator it is valid.


Now you have to edit your .htaccess file =P

Please add the code below so that instead of rss.php you could use news.xml or something else.

PHP Code
  1. RewriteEngine On
  2. RewriteRule ^(.*).xml$ rss.php


You can have anything with the extension of .xml which will link up to your news rss file!
ShadowMage's Avatar
Author:
Views:
3,295
Rating:
Posted on Thursday 18th October 2007 at 09:55 PM
Arudis
Arudis's Avatar
omg iv been looking all over the internet for a guide like this thanks