Textpattern tips, tutorials and code snippets

Who posted the latest comment

Sometimes you might want to display who posted the latest comment for a given article. Here’s how you do it:

In your article form

<txp:if_comments>
<p>[<txp:comments_count />]
Latest comment by <txp:comments form="comment_poster" sort="posted desc" limit="1" /></p>
</txp:if_comments>

The if_comments conditional checks for any comments associated with this article. If there are comments, display the latest comment using the comment_poster form.

Create comment_poster form

<txp:comment_name link="0" />

Place the above in a new form titled comment_poster and save as type comment.

Thanks to Els for the inspiration and code.

2 Comments Comment feed

Is there any way to extend this so you could have the latest comment (regardless of the article) on the homepage, for example? Hm. I guess you’d need a way to output the most recent article, only if it has at least one comment, and if not move on to the next and so on.

  • TNT
  • 5 February 2010

You can use the plugin wet_recent_comments for that.

Add a comment

Use Textile help to style your comments