Hey JonathanLaba,
I’ll do whatever I can to help.Please try to use this code:
<?php
// type = comment will only get "real" comments, no ping-/trackbacks
$comments = get_comments(array('type' => 'comment','post_id' => get_the_ID()));
$count=0;
foreach($comments as $comment) {
// if the comment has no parent, it´s the first of a thread
if( empty( $comment->comment_parent ) ) { $count++; }
}
switch($count) {
case 0: echo "NO COMMENT"; break;
case 1: echo "ONE COMMENT"; break;
default: echo "$count COMMENTS"; break;
}
?>
I hope it will solve your problem.
Good Luck
Juhi
If you’re using a premade theme – as opposed to a custom one you’ve made yourself – just a heads-up that the best way to make changes to a theme is to use a child theme, so your tweaks won’t be overwritten when updating the theme. Here are some guides in case you haven’t made one before:
http://codex.ww.wp.xz.cn/Child_Themes
http://op111.net/53/
http://vimeo.com/39023468
https://www.smashingmagazine.com/2016/01/create-customize-wordpress-child-theme/
(@jonathanlaba)
10 years, 4 months ago
Hi,
I’m currently using this function to display comments but I’d like to only count the comment threads and not include the nested elements.
<?php comments_number(‘(No Comments)’, ‘(One Comment)’, ‘(% Comments)’ );?>
I was took a look at this thread numbering plugin but I think that’s only for numbering like bullets.
https://en-ca.ww.wp.xz.cn/plugins/gregs-threaded-comment-numbering/
Any Help would be greatly appreciated