- Jul. 28th, 2006
- 1 comments
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_ENTITIES, ENT_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};)/","&" , 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');
?>
Related posts:
"Only One Wise Comment Banged Out Somewhere On The Internet ..."
Problem with RSS Feed in WordPress.
|
















