Textpattern tips, tutorials and code snippets

Recent comments output

I use the recent_comments tag to output the 5 most recent comments on TXP Tips.

The tag works very nicely, especially since the release of Textpattern 4.07 which added container tag functionality.

Single tag usage

<txp:recent_comments break="li" limit="5" wraptag="ul" class="category_list" />

This is what I have been using until today on TXP Tips. Works fine, but outputs the comments like so:

User's Name (Article Name) 

If you wish to change this format, you will need to use the tag as a container, then add your own formatting, like so:

<txp:recent_comments limit="5" break="" wraptag="ul" class="category_list">
<li><txp:comment_name link="0" />: <txp:comment_permlink><txp:title /></txp:comment_permlink></li>
</txp:recent_comments> 

This is what TXP Tips has now on the sidebar. Note the break="" which is necessary otherwise Textpattern adds a <br /> tag, and the link="0" in the comment_name tag which removes the link.

5 Comments Comment feed

A small edit to the above tip today – I had used <txp:permlink><txp:title /></txp:permlink> instead of <txp:comment_permlink><txp:title /></txp:comment_permlink>.

The problem with the former is that the comment #id is not outputted with <txp:permlink />, so the user is taken to the article rather than the comment itself. <txp:comment_permlink /> performs this function.

Noticed today that the recent comments output varies page by page.

This is due to a bug which I had initially reported back in April 2009 and was subsequently fixed in SVN. I totally forgot that I had reported the bug…!!

In case you use the code I posted above, just note that it will work fine in the upcoming 4.2.0 release.

Today installed the 4.2.0 RC1 and the recent comments links are now working properly. Thanks to the Dev team!

Thanks for this tip, it works on my blog too :-)

Just found the Txp Tips website. Very useful (even though I’ve used Txp for a while!). Thanks for the tip on recent comments. Have it working on my blog.

Add a comment

Use Textile help to style your comments