Display latest comments (global) with replies on a page

Trying to display the latest 50 comments (global, from all the posts) on a page (page.php)I am using this code:<?php

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) :?>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744839830a4596489.html

相关推荐

  • Display latest comments (global) with replies on a page

    Trying to display the latest 50 comments (global, from all the posts) on a page (page.php)I am using this code:<?php

    2天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信