admin管理员组文章数量:1404576
Trying to display the latest 50 comments (global, from all the posts) on a page (page.php)
I am using this code:
<?php $comments = get_comments('status=approve&number=50&type=comment&hierarchical=threaded');
foreach($comments as $comment) :?>
<?php $post = get_post($comment->comment_post_ID, 'OBJECT'); ?>
<li> <a href="<?php echo get_permalink($comment->comment_post_ID);?>#comment-<?php echo($comment->comment_ID);?>">
<?php echo $post->post_title; ?>
</a>
<?php echo($comment->comment_content);?>
</li> <br/>
<?php endforeach; ?>
It works fine, it shows the comments, but it doesn't show comment replies - I want to show replies too
`hierarchical=threaded`
should do the trick, but it doesn't. maybe because The parameter is ignored (forced to false) when $fields is 'ids' or 'counts'
But I don't know how to fix that
thanks!
Trying to display the latest 50 comments (global, from all the posts) on a page (page.php)
I am using this code:
<?php $comments = get_comments('status=approve&number=50&type=comment&hierarchical=threaded');
foreach($comments as $comment) :?>
<?php $post = get_post($comment->comment_post_ID, 'OBJECT'); ?>
<li> <a href="<?php echo get_permalink($comment->comment_post_ID);?>#comment-<?php echo($comment->comment_ID);?>">
<?php echo $post->post_title; ?>
</a>
<?php echo($comment->comment_content);?>
</li> <br/>
<?php endforeach; ?>
It works fine, it shows the comments, but it doesn't show comment replies - I want to show replies too
`hierarchical=threaded`
should do the trick, but it doesn't. maybe because The parameter is ignored (forced to false) when $fields is 'ids' or 'counts'
But I don't know how to fix that
thanks!
Share Improve this question edited Jan 13, 2020 at 15:31 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Jan 13, 2020 at 9:35 vyperlookvyperlook 1775 silver badges24 bronze badges1 Answer
Reset to default 0Try with array method, using reply post type with its parent.
<?php
$args = array(
'post_type' => 'reply',
'status' => 'approve',
'post_parent' => $postID,
'posts_per_page' => 50,
'orderby' => 'date',
'order' => 'ASC',
'hierarchical' => true,
'ignore_sticky_posts' => true,
);
foreach(get_comments($args) as $comment) :?>
本文标签: Display latest comments (global) with replies on a page
版权声明:本文标题:Display latest comments (global) with replies on a page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744839830a2627856.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论