Forum
Comments app - get comment count per post
I'm using the comments app to add comments to non-blog posts on a site.
I'm using a list-page and detail-page structure and each of the 'details' can have comments.
Is there any easy way of getting and showing the comment count for each post in a list page?
The only solution I've found is to use skip-template on the posts and then iterate through each one checking for comments - which seems cumbersome.
Thanks!
Documents: https://docs.grabaperch.com/functions/comments/perch-comments-count/
Thanks Robert, what I'm looking to do is access the comment count for a post within that post's template - something I'm not sure is possible.
The solution I've found is to use perch_comments_count() to grab the number then pass it in to perch_content_custom as a variable. Though this gets a little messy for long, paginated lists of posts.
For a listing, use the
each
callback optionThanks Drew - that's what I was looking for.
One last question: Is is possible to then access and display the
$item['content_count']
value within a template specified byperch_content_custom
?Ideally I'm after adding something like
<perch:content id="content_count">
within the template itself.Yes, that's how you'd access it (with your tag syntax corrected). You should see the value with
<perch:showall />
Thanks Drew - it was the syntax issue that had me stumped (D'oh!)