开发者

Wordpress: Issues trying to display all comments in one page

开发者 https://www.devze.com 2023-01-02 16:47 出处:网络
I\'m trying to modify my wordpress theme (inove) to display all comments in the same page instead of 50 comments per page.

I'm trying to modify my wordpress theme (inove) to display all comments in the same page instead of 50 comments per page.

I opened the comments.php file, commented out calls to paginate开发者_如何转开发_comments_links() and and set the wp_list_comments() as follows:

wp_list_comments('type=comment&callback=custom_comments&per_page=100&page=1');

The problem is, whenever someone posts a comments, the comment form appends '/comment-page-2/' to the URL after submitting the comment, even though I've specified that all comments to be displayed on the same page.

Any idea what I could be missing?

Appreciate your help


You can easily turn off comment pagination in your WordPress settings. Go to Settings > Discussion, then uncheck Break comments into pages with...

If the theme is well written, it should obey your settings correctly and display comments accordingly (and so there should be no need to edit the theme files).


<?php foreach (get_comments() as $comment): ?>
    <div>
      <?php echo $comment->comment_author; ?>
      <?php echo $comment->comment_content; ?>"
   </div>
<?php endforeach; ?>

For pagination, you can use the offset and number parameters of the get_comments() arguments:

<?php 
    $args = array(
        'number'=>20,
        'offset'=>0,
        'status'=>'approve',
    );
    foreach (get_comments($args) as $comment) {
        // ...
    }
?>
0

精彩评论

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