Jul 28

RSS Made Even Simpler

Posted by Jaimie Sirovich on Jul. 28th, 2006. 1 comments — voice your opinion.

NEED A GREAT WEB SITE? NEED IT TO BE SEARCH-ENGINE-FRIENDLY?

SEO Egghead is a web development firm dedicated to creating custom, search engine optimized web site applications. We specialize in eCommerce and content management web sites that not only render information beautifully to the human, but also satisfy the "third browser" — the search engine. To us, search engines are people too. Click here to talk to us. We'd love to help!
X

Syndication isn't only for blogs; it can be used for any type of site with any sort of infomation. Blogs typically already include robust feed support (including both RSS & Atom), but what about if you want to create a feed for a site that isn't a blog? Easy — use the below class to do it.

So what does this have to do with SEO? Feeds are effective vehicles to disseminate information. Your site can release information via a feed, usually abbreviated, then include a link to the full content. This will, over time, garner many links from various sites that want to syndicate the information. It is wise to abbreviate the amount of information provided, as the full content appearing on various sites may cause duplicate content problems.

Note: It is also likely that lots of spammers will use the feed over time to create pages with Frankenstein content MFA-type sites. I've never been hurt by this, though. So here is the code.

<?

class MakeRSSFeed
{

    var $_title;
    var 
$_link;
    var 
$_description;
    var 
$_language;
    
    var 
$_items;
    
    function 
MakeRSSFeed($title$link$description$language 'en-us'$items = array()) 
    {
        
$this->_title $title;
        
$this->_link $link;
        
$this->_description $description;
        
$this->_language $language;
        
        
$this->_items $items;
    }
    
    function 
addItem($title$link$description$additional_fields = array())
    {
        
$this->_items[] = array_merge(array('title' => $title'link' => $link'description' => $description), $additional_fields);
    }
    
    function 
get($version '0.91')
    {
        
ob_start();
        
header('Content-type: text/xml');
        
?>
        <rss version="<?=$version?>">
        <channel>
        <title><?=MakeRSSFeed::_escapeXML($this->_title)?></title>
        <link><?=MakeRSSFeed::_escapeXML($this->_link)?></link>
        <description><?=MakeRSSFeed::_escapeXML($this->_description)?></description>
        <language><?=MakeRSSFeed::_escapeXML($this->_language)?></language>
        
        <? foreach ($this->_items as $i): ?>
            <item>
            <?
            
foreach ($i as $index => $_i) {
                echo 
"<$index>" MakeRSSFeed::_escapeXML($_i) . "</$index>";
            }
            
?>            
            </item>            
        <? endforeach; ?>
        
        </channel>
        </rss> 
        <?
        
        
return ob_get_clean();    
    }    

    function _escapeXML($str)
    {
        
$translation get_html_translation_table(HTML_ENTITIESENT_QUOTES);
        
        foreach (
$translation as $key => $value)
            
$translation[$key] = '&#'.ord($key).';';
        
$translation[chr(38)] = '&';    
        
        return 
preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&#38;" strtr($string$translation));

    }

    
}

?>

An RSS feed could then be created as follows:

<?

$rss_feed = new MakeRSSFeed('My RSS Feed''http://www.example.com/news.html''Example dot Com News');

$rss_feed->addItem('News Story''http://www.example.com/news1.html''Story 1');
$rss_feed->addItem('News Story 2''http://www.example.com/news2.html''Story 2');    

echo $rss_feed->get('2.0');

?>

Tell an amigo:
  • Sphinn
  • Digg
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Facebook



Related posts:
Using Syndicated Content in Moderation Syndicated content is content that is authored by another source...
Social Bookmarking PHP Library Many of us use social bookmarking sites — del.icio.us, digg,...
How You Can Stop Dirty Feed Scrapers In 3 Easy Steps Stealing is wrong; but some people just don't seem to...
Matt Cutts Gems: Part II This is a summary of the videos located at http://www.mattcutts.com/blog/another-two-videos/...
Site Review: www.elitehosts.com Elite Hosts is a smaller full-service web hosting company.  If...




"Only One Wise Comment Banged Out Somewhere On The Internet ..."


Jimmy

Problem with RSS Feed in WordPress.
I have a subdomain that I installed wordpress for another blog site, but the subdomain site's rss feed points to my parent site.
Can anyone come up with any suggestions?



Care To Bang On The Keys ... ?

BECOME AN EGGHEAD. SUBSCRIBE TO OUR RSS FEED!

Learn to be as nerdy as we are by never missing our latest blog entries. Receive great tips, tricks, and ideas on improving your web site every day! Subscribe via our RSS Feed or use the chicklets in the sidebar.