Any way to get count of comments for a post?

Topics: Business Logic Layer
Jan 12, 2011 at 5:16 AM

On my main blog page i want to be able to display the comment count next to each post - any way to do that? Tried looking around in the code for the properties of Posts and comments but didn't see anything that looked like a total count of comments.

Jan 12, 2011 at 7:04 AM

In your theme's PostView.ascx file, you can get the total comment counts via:

<%= Post.Comments.Count %>

Or if you look at the Standard theme's PostView.ascx (this one here), you can see it uses

<%= Post.ApprovedComments.Count %>

This will be displayed for each post shown on both the homepage as well as on the individual post page.

Jan 12, 2011 at 4:03 PM

Thanks - can you tell me where in the doc's this is listed? I don't want to have to keep bugging you for every little thing. I thought I looked through the docs but I couldn't find this.


Jan 13, 2011 at 7:32 AM

I took that from the Standard theme.  But on this documentation page, there is some more information available.  Post.Comments.Count is on the page a couple of times too.

Jan 13, 2011 at 7:47 AM

thanks, i see it now. guess i need to look a little harder next time.