/ Published in: PHP
                    
                                        
If you syndicate your content with an RSS feed it can help to drive additional traffic to the content pages.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
// 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);
URL: http://coboldinosaur.com/pages/creating-rss-feeds-for-your-site.html
Comments
 Subscribe to comments
                    Subscribe to comments
                
                