1

I created a custom comments_list() function, it works fine, the only problem is to show child comments inside the parent div. It works well with first and second depth levels but not for others.

This is my code:

/* -----------------------------------------------------------------------------
 * Comments custom functions
 * -------------------------------------------------------------------------- */
//Custom comments lst
function t_one_comments_list( $comment, $args, $depth ) {
    $GLOBALS['comment'] = $comment;
    switch( $comment->comment_type ) :
        case 'pingback' :
        case 'trackback' : ?>
        <li <?php comment_class(); ?> id="comment<?php comment_ID(); ?>">
            <div class="back-link"><?php comment_author_link(); ?></div>
    <?php
            break;
        default :
    ?>
</li>
<?php if ($depth == 1) {?>
   <div <?php comment_class('media'); ?> id="comment-<?php comment_ID(); ?>">
        <?php if ($comment->comment_approved == '0') : ?>
            <p><?php _e('Your comment is awaiting moderation.', 't_one') ?></p>
        <?php endif; ?>
            <div class="pull-left">
                <?php echo get_avatar( $comment, 100 ); ?>
            </div>
            <div class="media-body">
                <div class="well">
                    <div class="media-heading">
                        <strong><?php comment_author(); ?></strong>&nbsp; <small><?php printf( __('%1$s', 't_one'), get_comment_date()) ?></small>
                        <?php edit_comment_link(__(' Edit', 't_one'), ' ', '' ); ?>
                        <?php comment_reply_link( array_merge( $args, array( 
                                'reply_text' => __( '<i class="fa fa-repeat"></i>Reply', 't_one' ),
                                'depth' => $depth,
                                'max_depth' => $args['max_depth'] 
                                ) ) ); ?>
                    </div>
                    <p><?php comment_text() ?></p>
            </div>
            <?php if ( $depth + 1) { ?>
            <div <?php comment_class('media'); ?> id="comment-<?php comment_ID(); ?>">
        <?php if ($comment->comment_approved == '0') : ?>
            <p><?php _e('Your comment is awaiting moderation.', 't_one') ?></p>
        <?php endif; ?>
            <div class="pull-left">
                <?php echo get_avatar( $comment, 100 ); ?>
            </div>
            <div class="media-body">
                <div class="well">
                    <div class="media-heading">
                        <strong><?php comment_author(); ?></strong>&nbsp; <small><?php printf( __('%1$s', 't_one'), get_comment_date()) ?></small>
                        <?php edit_comment_link(__(' Edit', 't_one'), ' ', '' ); ?>
                        <?php comment_reply_link( array_merge( $args, array( 
                                'reply_text' => __( '<i class="fa fa-repeat"></i>Reply', 't_one' ),
                                'depth' => $depth,
                                'max_depth' => $args['max_depth'] 
                                ) ) ); ?>
                    </div>
                    <p><?php comment_text() ?></p>
            </div>
            </div>

            <?php } ?>
            </div>
         <?php } ?>
    <?php // End the default styling of comment
        break;
    endswitch;
}

What is the correct way to use $depth?

Thanks in advance!

0

I'm afraid this is the problem:

Wrong:

<?php if ( $depth + 1) { ?>

Correct:

<?php if ( $depth > 1) { ?>

That is what I think...

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.