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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

Try 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