2

I have a custom template for to show my comments.

For some reason, there are not nested while looking in the back-end of Wordpress, I see that some comments have a parent.

They are simply displayed starting with the most recent on top.

So I guess I call the comments in a wrong way. Here is my code:

<?php
$args = array(
);

// The Query
$comments_query = new WP_Comment_Query;
$comments = $comments_query->query( $args );

// Comment Loop
if ( $comments ) {
echo '<div class="comments">';
echo '<span>';
comments_number( 'No comment', 'One comment', '% comments' );
echo '</span>';
foreach ( $comments as $comment ) { ?>

    <div class="comment <?php if( '0' != $comment->comment_parent ) { echo "depth-2"; } ?>" id="comment-<?php comment_ID() ?>">

                <a href="#discussion" class="reply" onclick="javascript:document.getElementById('comment_parent').value='<?php comment_ID() ?>'"><i class="icon-reply"></i>answer</a>
                <a href="#discussion" class="cancel-reply" onclick="javascript:document.getElementById('comment_parent').value='0'"><i class="icon-cancel-circled"></i>annuler</a>
                <?php echo  get_avatar(get_comment_author_email($comment->comment_ID), 44); ?>
                <strong><?php echo get_comment_author_link(); ?></strong>
                <small class="timeago" title="<?php comment_date('c'); ?>"></small>
                <?php if( !$comment->comment_approved ) : ?>
                <em class="comment-awaiting-moderation">Awaiting moderation</em>
                <?php else: comment_text(); ?>
                <?php endif; ?>
</div>
<?php } ?>
                                        </div>
    <?php 
} else {
echo '';
}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.