For a post I'd like to count the comment threads and not include nested replys in the count.

Currently I'm using a simple comment count, comments_number( $zero, $one, $more );

What would be the best way to get the number of comment threads in a post?

Any suggestions would be greatly appreciated.


You could try this, must be used in the loop:


// type = comment will only get "real" comments, no ping-/trackbacks
$comments = get_comments(array('type' => 'comment'));

$threads = 0;
foreach($comments as $comment) {
   // if the comment has no parent, it´s the first of a thread
   if($comment->parent == '') { $threads++; }

switch($threads) {
   case 0: echo "There are no comments so far."; break;
   case 1: echo "There is one thread..."; break;
   default: echo "There are '.$threads.' comment threads going on."; break;

  • Thanks, How would I format this complete it to just replace the existing format of? <?php comments_number( $zero, $one, $more ); ?> – Jon Laba Jan 25 '16 at 2:25
  • I updated my code. Basically, the thread count is saved in $threads, so you can use it in several different ways... – flomei Jan 25 '16 at 7:21
  • Did this work for you? If so, I´d enjoy if you mark my answer as the right solution. – flomei Jan 26 '16 at 1:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.