Implementing the wfw:commentRSS API into the wordpress RSS feed.
July 13th, 2005 · Posted in Uncategorized ·
30 Days of writing: Day 12
This morning I added a few features to my RSS feed. In the interests of public knowledge (and so I don’t have to keep visiting pages to read comments), I now present a short article on implementing the commentRSS API within wordpress’ RSS 2 feed.
The commentRSS API allows feed aggregators to attach a comment feed to each item in the RSS feed, giving access to the comments on a post without having to visit the site to read them. Handy.
To start with, open up wp-rss2.php in a text editor and add the line starting wfw: in the <item> </item> node:
<item>
<title>< ?php the_title_rss() ?></title>
<wfw :commentRss>< ?php echo comments_rss(); ?></wfw>
...
</item>
Close your text editor because your RSS aggregator can now associate the appropriate comment feed with your all-purpose feed. Yep, that’s it. A single line.
You want to make it a bit fancier still?
OK, how about we add an image to the channel (so your aggregator can show a little picture of you above your posts) and a count of the comments to be included.
The image code is fairly straight-forward again, just add the <image></image> node under the <channel> </channel> node:
<channel>
<title>< ?php bloginfo_rss('name'); ?></title>
<image>
<title>The Rodeo</title>
<url>http://...(etc).../images/ussmall.png</url>
<link>< ?php bloginfo_rss('url') ?></link>
</image>
...
</channel>
This example assumes you want to label your image ‘The Rodeo’ and use a small picture of my wife and I as your image. Just change the title to suit and specify the URL to where your picture is located.
Once again, a fairly simple change. Adding the number of comments should round off the evening’s lesson nicely.
Firstly the following namespace needs to be defined in the<rss> </rss> node:
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
>
...
</rss>
Then add the slash:... line in the <item> </item> node:
<wfw:commentRss>< ?php echo comments_rss(); ?></wfw> <slash:comments>< ?php echo get_comments_number( $id ); ?></slash:comments>
All finished.
Those few simple changes will make your wordpress RSS feed look a bit cooler in any aggregator that can handle those extensions.
Note: I realise this looks terrible, but I was having huge issues with getting the code to display at all - I’ll try and neaten it up at some point in the future.
-RodeoClown
July 18th, 2005 at 12:41 pm
Just to say, I still get the feeds separately.
Is there a separate URL or something?
July 18th, 2005 at 1:02 pm
No separate feed. Maybe your feed reader can’t use the commentsRSS namespace.
It works perfectly for me. I don’t know why it doesn’t work for you, sorry. When you say you get the feeds separately what do you mean?
Are you talking about my site, or did you implement it on yours?
In other news, the new team leader at work just discovered the ‘Thigh Fives’ comic posted between our desks. He thought it was ridiculous, but funny.
July 19th, 2005 at 10:11 pm
I declare! A positive sign!
PS. I don’t think my RSS feeds work anymore. Does it look like I’ve posted anything in the last week to you?
July 20th, 2005 at 4:01 am
I think the last thing I got from your feed was the 2nd dinner you made (I think it was a fish thing).
December 26th, 2005 at 9:33 pm
[…] ordPress 2.0 Beta. I also want to update my RSS feed to embed a funky picture in the feed (like Ian’s). If anyone’s got some thoughts about the current prototype (what they hate/li […]
February 17th, 2007 at 8:45 am
quick tip: I think the end element needs the namespace as well, so this:
<slash:comments></slash>
should actually be this:
<slash:comments></slash:comments>
February 17th, 2007 at 6:16 pm
Thanks for that AJ, I’ve fixed it now.