WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have defined a walker in function.php to display comments in a certain way. I use the following code:

function speld_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
global $comment_count;
<!-- <?php echo $comment_count; ?> -->
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>">
    <div class="comment-author_pic">
        <?php echo get_avatar($comment,$size='48',$default='http://www.speld.nl/wp-content/themes/speld5/images/avatar.png' ); ?>
        <p class="comment_number"><?php echo $comment_count; ?></p>

    <div class="comment_text">
        <?php if ($comment->comment_approved == '0') : ?>
        <em><?php _e('Een moment geduld, uw reactie wordt beoordeeld door de Speld Waarheidscommissie.') ?></em>
        <?php endif; ?>
        <div class="comment-meta commentmetadata">
            <?php printf(__('%s'), get_comment_author_link()) ?> &bull;
            <a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s, %2$s'), get_comment_date(),  get_comment_time()) ?></a>
            <?php // we want to add 'Zie profiel' here.. comment_author_link()  ?>
        <?php comment_text() ?>
        <div class="comment_tools">
            <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'reply_text'=>'Reageer', 'max_depth' => $args['max_depth']))) ?>

I've also enabled reacting to a comment (1 level deep).

The problem is in the comment_count variable. Whenever somebody replies to a comment, the numbering for all comments below the reply shifts one number down. I'd like to prevent that from happening.

Is it possible to make an if statement in the walker that allows reactions to a comment to not contain the comment_count variable? Any help would be greatly appreciated!

share|improve this question
up vote 2 down vote accepted

Just use the $depth arg:

if ( $depth ) {
  // it's a child comment
} else {
  // it's a parent comment
share|improve this answer
You mean if ( $depth==2 ) { // it's a child comment } else { // it's a parent comment } right? – Squrler Jul 7 '11 at 11:50
Yeah, if $depth starts at 1. More general would be if ( $depth > 1 ). – scribu Jul 7 '11 at 13:16
Awesome, thanks! – Squrler Jul 7 '11 at 14:41

Your Answer


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.