I am actually displaying a number beside my comments putting $counter = 0; before wp_list_comments in comments.php and

global $counter;

inside the comments callback function in functions.php

Now this is working fine, but since I'm using threaded comments, my numbers are looking strange (1,4,10,14) because it's counting also the child comments.

Is there a way to count only parent comments (1,2,3,4,5...)?



You can check if the comment has a parent and only count if not:

global $counter;
if ($comment->parent == 0){
  • Thanks, I already tried this but it's still counting parents and childs. – Andycap May 15 '11 at 12:49
  • Then there must be something else since this simple code can only count parents, paste your code here for us – Bainternet May 15 '11 at 13:05
  • Sorry, I messed up something with the echo, it's working. – Andycap May 15 '11 at 16:01

This Q is close to a dublicate of this Question, that you already asked. The only thing you have to make different, is that you switch the content of the if/else statement.

  • Yes Kaiser, you're right, but I got rid of the plugin and I was looking for a really simple solution. Forgive me, I'm not very smart with programming, I'm a designer, but trying to learn something more. thanks – Andycap May 15 '11 at 16:04

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.