Display the Number of Comments Per Item

CMS template language includes a class that tracks the number of comments per content item. Using the base properties in the table below, you can configure a display template to display the number of user Comments submitted per Web page or other content item, including the time stamp of the most recent comment. You can use these properties in the following display templates:

  • A Web-page content type display template containing a Comment Form component

  • A list display template that lists items containing Comment Form components

  • A Post/Comment content type display template

The following base properties are available for use in tracking the number of Comments per content item; they can also be tested by means of an if test.

Base Property Description
totalcomments The number of user Comments.
lastcommentdate The date of the last Comment written/submitted.
firstcommentdate The date of the first Comment written/submitted.

Here is an example of a simple list template configured to display the number of Comments per item:

<H1>Latest Press Releases</H1>
<HR>
<t:list maxlength="5">
<P><B><A href="${url}"><t:value id=title>PR Title</t:value></A></B>
<BR><t:value id=description>Description of the press release.</t:value>

<t:if test="totalcomments > 0"><B>Comments:</B> <A href="xxx"><t:valueid=totalComments>Number Here</t:value></A>
<br>Last Comment Date: <t:value id="lastcommentdate"/>
<br>First Comment Date: <t:value id="firstcommentdate"/></t:if>

</t:list></B>

And here is an example of how the Comments count will display on a live page, in this case a blog post:

My Blog Post

I had a wonderful day today...

Comments (12) most recent at 4/12/09 4:45 pm | Share This