Showing number of comments on blog index page (or elsewhere)
If you want to show the number of comments for your blog posts somewhere else on the article page, or on the blog index page, you can add this code to your theme to display this information.
{% comment %} Ensure you add this in a file that has access to the {{ article }} object {% endcomment %} {% assign parentComments = article.metafields.bb_comments.comment_list %} {% assign totalComments = parentComments.size %} {% for parent in parentComments %} {% assign totalComments = totalComments | plus: parent.replies.size %} {% assign level1Replies = parent.replies %} {% for level1 in level1Replies %} {% assign totalComments = totalComments | plus: level1.replies.size %} {% assign level2Replies = level1.replies %} {% for level2 in level2Replies %} {% assign totalComments = totalComments | plus: level2.replies.size %} {% assign level3Replies = level2.replies %} {% for level3 in level3Replies %} {% assign totalComments = totalComments | plus: level3.replies.size %} {% assign level4Replies = level3.replies %} {% for level4 in level4Replies %} {% assign totalComments = totalComments | plus: level4.replies.size %} {% assign level5Replies = level4.replies %} {% for level5 in level5Replies %} {% assign totalComments = totalComments | plus: level5.replies.size %} {% endfor %} {% endfor %} {% endfor %} {% endfor %} {% endfor %} {% endfor %} {% if totalComments > 0 %} {{ totalComments }} comments on this article {% endif %} {% endif %}
This is how it looks on my development theme:
Give it a try and let us know if you have any issues!