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) :?>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744839830a4596489.html
评论列表(0条)