Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

global $counter;
$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...)?

Thanks

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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

global $counter;
if ($comment->parent == 0){
  $counter++; 
}
share|improve this answer
    
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.

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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