Revision: 69827
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at September 16, 2015 01:37 by COBOLdinosaur
Initial Code
// your DB connection goes here define('LINKBASE','http://yoursite.com/'); $sql=$yourDB->query("SELECT pageTitle,pageLink,pageDesc,pageDate FROM pageTab ORDER BY pageDate DESC LIMIT 10"); $cnt=$sql->rowCount(); // NOW WE NEED TO DO THE HEADING FOR THE FEED $feedMainLink=LINKBASE.'feedname.xml'; $mainDate=date("D, d M Y H:i:s O"); // format the date to the rss 2.0 standard $rssfeed='<?xml version="1.0" encoding="UTF-8"?>'; // WE'LL USE HEREDOC TO BUILD THE HEADING LINES $rssfeed.=<<<HEAD <rss version="2.0"> <channel> <title>TITLE of the FEED</title> <link>$feedMainLink</link> <description>A selection of the latest articles, editorials and script snippets</description> <pubDate>$mainDate</pubDate> HEAD; // NOW WE CAN LOOP OUT THE ITEMS $rowBlock=$sql->fetch(PDO::FETCH_ASSOC); for ($i=0;$i<$cnt;$i++); { $row=$rowBlock[$i]; $PgLink=LINKBASE.$row['pageLink']; $pubDate=date("D, d M Y H:i:s O", strtotime($row['pageDate'])); $rssfeed.=<<<ITEM <item> <title>{$row['pageTitle']}</title> <description>{$row['pageDesc']}...</description> <link>$pageLink</link> <pubDate>$pubDate</pubDate> </item> ITEM; } } $rssfeed .= '</channel>'; $rssfeed .= '</rss>'; file_put_contents('feedname.xml', $rssfeed);
Initial URL
http://coboldinosaur.com/pages/creating-rss-feeds-for-your-site.html
Initial Description
If you syndicate your content with an RSS feed it can help to drive additional traffic to the content pages.
Initial Title
Creating an RSS Feed From Your Site
Initial Tags
php, xml
Initial Language
PHP