Subscribe to RSS Subscribe to Comments

Alan Blaine Whitney

Comments in RSS feed

For the most part, every project I do starts with cakephp, jquery and 960 grid.  Just about everytime I need to do an rss feed, I follow the directions in the cook book.  This has worked great.

Today I got wondering about the how feedburner does the comment count within their feed flare.  It seems to work with word press.  Auto-magically.  I wanted to make it happen outside of wordpress.  Turns out that it is pretty easy.  It uses a new namespace in the XML, wfw.

To add that namespace, one first needs to put a new xmlns attribuate in the rss tag, like below.

<rss xmlns:wfw="http://wellformedweb.org/CommentAPI/"  version="2.0">

Well, you would think that is pretty easy in cake, add an array to some $rss method call.  Well, this was a rare instance in cake where I couldn’t quite get it to work.  So I had to make changes to the rss help.  First, copy the rss helper from  cake/libs/view/helpers/rss.php to app/views/helpers/rss.php. Once it’s copied, I manually changed the document method to this

	function document($attrib = array(), $content = null) {
		if ($content === null) {
			$content = $attrib;
			$attrib = array();
		}
		if (!isset($attrib['version']) || empty($attrib['version'])) {
			$attrib['version'] = $this->version;
		}
 
		if (!isset($attrib['xmlns:wfw']) || empty($attrib['xmlns:wfw'])) {
			$attrib['xmlns:wfw'] = 'http://wellformedweb.org/CommentAPI/';
		}
 
		return $this->elem('rss', $attrib, $content);
	}

Now just one last change to make, in the my view, which was located at app/views/articles/rss/feed.ctp, where the item is added

        echo  $rss->item(array(), array(
            'title' => $article['Article']['title'],
			'comments' => array_merge(array('#' => 'comments'), $url),
			'wfw:commentRss' => 'http://' . $_SERVER['SERVER_NAME'] . '/comments/' . 
				'index/' . $article['Article']['id'] . '.rss',
			'link' => $url,
			'guid' => array('url' => $url, 'isPermaLink' => 'true'),
            'description' =>  $bodyText,
            'pubDate' => $article['Article']['created']));

And that is about it, then it just worked with feedburner’s feed flare comment counter. Just like wordpress.

No comments yet. Be the first.

Leave a reply

Based on FluidityTheme Redesigned by Kaushal Sheth Sponsored by Send Flowers