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!

1 Answer 1


Just use the $depth arg:

if ( $depth ) {
  // it's a child comment
} else {
  // it's a parent comment
  • You mean if ( $depth==2 ) { // it's a child comment } else { // it's a parent comment } right?
    – Squrler
    Commented Jul 7, 2011 at 11:50
  • 2
    Yeah, if $depth starts at 1. More general would be if ( $depth > 1 ).
    – scribu
    Commented Jul 7, 2011 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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