开发者

Displaying threaded comments without wp_list_comments()

I am creating a custom comment layout, therefor I'm not using wp_list_comments(). My problem is that I can't seem to figure out for to effectively display replied comments in one another (threaded).

So far I have it so it only show the top most layer of comments.

<ol class="commentlist">
    <?php foreach ($comments as $comment) : ?>
        <?php if($comment->comment_parent == 0): ?>
        <li class="comment">

            <div class="main">
                <div class="name">
                    <?php if(get_comment_author_url()): ?>
                        <a href="<?php comment_author_url(); ?>"><?php comment_author(); ?></a>
                    <?php else: ?>
                        <?php comment_author(); ?>
                    <?php endif; ?>
                </div>
                <div class="text"><?php comment_text(); ?></div>
            </div>
            <div class="info">
                <?= get_avatar($comment, $size = '90'); ?>
                <div class="month"><?= comment_date('M'); ?></div>
                <div class="day"><?= comment_date('dS'); ?></div>
                <div class="year"><?= comment_date('Y'); ?></div>
            </div>

            <div class="clear"></div>
        </li>开发者_如何学编程;
        <?php endif; ?>
    <?php endforeach; ?>
</ol>   

I know want to display the comments that are replies within this comment.


I have seen your code, i think there is restriction for the child comments. you had condition where parent comments will displaying only.

You need to create one more class OR CSS for child comments and for that also need to run loop inside this FOREACH loop and displaying only that childes where Parent would be the

$comment->comment_parent

.

I think i am right if i get your prob.

Thanks.


I have figured out how to achieve threaded comments while using a custom layout.

Inside of your functions.php file place the following code:

<?php function comment_layout($comment, $args, $depth) {
    $GLOBALS['comment'] = $comment; ?>
            
            // Your custom layout here

<?php } ?>

Now, inside your comments.php file simply places the following where you would like the comments to appear.

<?php wp_list_comments( array( 'callback' => 'comment_layout' ) ); ?>

What will this do is, loop through all the comments (in the correct order) and call your custom layout to display the comment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜