As hinted to last week, I now have my WordPress installation output comments as RSS 1.0, both as a blog-wide feed and as a feed per post.
At the core they are just like other feeds, but comments are a little more diverse than posts. There are regular comments, entered in the comment form for each post, and PingBack‘s and TrackBack‘s, both of which are “remote” — a notification of reference from somewhere else.
Each of these three types of comments are different from each other, and need to be handled differently.
All three types are considered to be an rss:item
, with the usual properties title
, description
and link
, in addition to the time of submission.
Regular Comments
WordPress requests name, e-mail address, and URI for a comment author. These make fine properties for a foaf:Person
, except for the fact that the relationship between the author and the URI isn’t identified. So even though it would be tempting to label it as foaf:weblog
or foaf:homepage
, I decided to go with foaf:made
, assuming that the comment author would only enter a URI for something that (s)he created.
Note that this is another case where a superproperty of foaf:weblog
and foaf:homepage
would be handy, one that is also an InverseFunctionalProperty, the same issue arises with Atom.
The e-mail address is obscured by using foaf:mbox_sha1sum
instead of foaf:mbox
, but only if a sufficiently advanced version of PHP is being used, it needs either the built-in sha1
function (available since 4.3.0) or the mhash library (enabled at PHP compile time).
Example: Binary Relations: Comments
PingBacks
The PingBack implementation in WordPress records the URI that has pinged, the title of the document at that URI, and an excerpt of the text surrounding the link to the post being commented on.
This is not enough to identify a person, so instead I issue a statement about the fact that the pinging document is referencing the post, with dcterms:references
, in addition to stating the title and description of the document and the fact that there is a dc:relation
between the comment and the document.
Example: Binary Relations: Comments on FOAF output from WordPress
TrackBacks
TrackBacks offer basically the same properties as PingBacks, but also the title of the weblog the tracking document belongs to. This is added to an anonymous resource — the URI for the weblog isn’t known — as dc:title
, with the tracking page referencing the weblog by dcterms:isPartOf
.
Example: Binary Relations: Comments on Easy RDF-parsing with PHP
Installation
Installation of this hack consists primarily of placing a copy of wp-comments-rdf.txt
(rename to wp-comments-rdf.php
) in the root directory. Unfortunately, a few changes to the existing WordPress files are also needed to get eveything working perfectly.
In /wp-feed.php
the default feed flavour should be changed to rdf:
if ($feed == '' || $feed == 'feed') { // TODO: Get default feed from options DB. $feed = 'rss2rdf'; }
Also, in the same file, the name of the comment feed file needs to be changed:
if ( (($p != '') && ($p != 'all')) || ($name != '') || ($withcomments == 1) ) { require('wp-commentsrss2-rdf.php'); } else {
Finally, links to the new feeds should be inserted on the HTML pages. To include a link in the meta section, add the following to /index.php
, near the link to the “regular” feed(s):
<li><a href="<?php bloginfo('siteurl'); ?>/comments/feed/rdf" title="<?php _e('Syndicate this site's comments using RSS'); ?>"><?php _e('<abbr title="RDF Site Summary">RSS</abbr> 1.0 (Comments)'); ?></a></li>
To include a link to the comment feed for each post, edit /wp-comments.php
to include the following line somewhere — a good place to put it is below the list of comments:
<p class="commentsfeed"><a href="<?php print get_permalink() ?>/rdf" title="<?php _e('Syndicate this post's comments using RSS'); ?>"><?php _e('<abbr title="RDF Site Summary">RSS</abbr> 1.0 feed for comments on '); the_title(); ?></a></p>
That should do it. Really.
4 thoughts on “Semantic Comments Feeds from WordPress”
Comments are closed.