verbb / comments

A Craft CMS plugin for managing comments directly within the CMS.
Other
137 stars 35 forks source link

Count the number of comments on an entry? #262

Closed mitchellgemma closed 2 years ago

mitchellgemma commented 2 years ago

Question

Is it possible to count the number of comments on an entry? I have a channel with entries, and have comments enabled for each entry. I am just trying to get a number for the total comments on a single entry. Nested replies are disabled, so it is only 1 level of comments. Thanks!

Additional context

No response

lucosius commented 2 years ago

This one should help:

 {% set params = {
    ownerId: entry.id
} %}
{{ craft.comments.fetch(params) | length }}
mitchellgemma commented 2 years ago

That did the trick, thank you!

engram-design commented 2 years ago

Word of warning that you should use {{ craft.comments.fetch(params).all() | length }} or {{ craft.comments.fetch(params).count() }} as without these functions, you're getting the length of the CommentQuery, which will give you unexpected results.