Recent comments

A recent comments list is a neat innovation that lots of people are using (Burningbird has a set of instructions for MT). Seemed like a nice idea, so here’s some instructions for doing the same with Vellum.

You need to create a template for recent comments, tell Vellum to build said template, and then include the built file somewhere on your pages.

First, the template, in vellum/templates/recentcomments.tmpl:

<%
COMMENTS_TO_DISPLAY = 8
import vellum.plugins.audience,vellum.Entry

comments = vellum.plugins.audience.all_audience()
comments = filter(lambda x:x.type=='comment',comments)

comments.sort(lambda x,y:cmp(y.posted,x.posted))

print '<ul>'
for c in comments[:COMMENTS_TO_DISPLAY]:
  e = vellum.Entry.get(c.entryid)
  print '<li>%s on <a href="%s#au%s">%s</a></li>' % (c.ref,e.permalink,c.id,e.ti
tle)
end
print '</ul>'
%>

(this has changed from my original posting: use this version, because it doesn’t have to individually load all the entries from disk, which is very very slow indeed.)

Next, tell Vellum to build the template. Go to the configuration screen for your weblog (“Configure” from the front page) and, in the templates section, add a new template:

  • Template name: Recent comments
  • Template filename: templates/recentcomments.tmpl
  • Permalinks to here: [leave unselected]
  • Permalink expression: [leave blank]
  • Sort expression: [leave blank]
  • Output page: "recentcomments.html"
  • Page header: "Recent Comments"

(the quotes in the last two are important!)

Now, rebuild your weblog. You can include the recentcomments.html file somewhere, but bear in mind that, owing to Vellum’s funky caching, it won’t be there until it’s requested specifically. I get around this by having the “include” from my main page actually do an HTTP request to localhost to get the file.

More in the discussion (powered by webmentions)

  • (no mentions, yet.)