Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have setup in admin to have 5 comments per post display, which is what I want, and newest at the top.

But the problem is when a 6th comment is made it is the only one displayed and you can read the previous comments which will display 5.

What I would like it to do is always display 5 comments, when 6th is made the oldest pushed to the next page.

Thanks, Matt

share|improve this question
    
Please show your code. –  kaiser Aug 29 '12 at 18:58
add comment

4 Answers 4

Try adding the following code to your comments.php template file (where you want the "next page" / "prev page" links displayed):

<?php paginate_comments_links(); ?> 

This should enable multiple pages for your comments.

Also, check out this Codex page (paginate_comments_links) for more information. Hope this helps ;)

share|improve this answer
    
Thats not quite what I am after. The issue is when you set WP to display 5 comments, when a 6th is added it will only show that 6th comment. I want it to show 5 at all times, so when a 6th is added you would see comment 2, 3, 4, 5, 6 and comment 1 would be on the 2nd page. –  matt Aug 27 '12 at 21:31
add comment
get_comments(array(
 'number' => 5,
 'order' => 'desc'
))

You will have to alter your template files and modify get_comments() function as above.

Hope that helps.

share|improve this answer
    
Thank you, but where would I find the code I need to modify, im using the twenty-ten theme. Thanks! –  matt Aug 29 '12 at 17:45
add comment
up vote 1 down vote accepted

Ended up solving this with the following code:

<ol class="commentlist">
        <?php $comments = array_reverse($comments, true); ?>
            <?php
                /* Loop through and list the comments. Tell wp_list_comments()
                 * to use twentyten_comment() to format the comments.
                 * If you want to overload this in a child theme then you can
                 * define twentyten_comment() and that will be used instead.
                 * See twentyten_comment() in twentyten/functions.php for more.
                 */
                wp_list_comments( array( 'callback' => 'twentyten_comment','status' => 'approve&number=5','order' => 'asc' ) );
            ?>
        </ol>
share|improve this answer
    
Does that paginate the comments though, or only show the last 5? Using a customized walker (as an argument to wp_list_comments), you should be able to easily customize where the pagination starts and which direction it goes, and not have to hack the status attribute either (you never know when that kind of a hack will break) ;) –  mltsy Aug 30 '12 at 19:11
    
Oh, I see, you just reversed the array, so it's still paginated? There is also a filter for modifying the comments array (called comments_array), in case you'd rather put your logic outside of the template: codex.wordpress.org/Plugin_API/… And the source for it is here: core.trac.wordpress.org/browser/trunk/wp-includes/… –  mltsy Aug 30 '12 at 19:23
add comment

I believe what you want to do (change the way comments are paginated by starting with the last comments and working back rather than starting with the first comments and working forward to create pages) is controlled by a walker - specifically the Walker_Comment class - which is instantiated on line 1490 and used on line 1492 of this file, in the wp_list_comments function: http://core.trac.wordpress.org/browser/trunk/wp-includes/comment-template.php

You can extend and pass in your own extended walker class to wp_list_comments (by modifying or writing a custom comments.php template). This article explains a little bit about how to write a custom walker: http://bugssite.org/blog/2009/12/08/wordpress-custom-walker-tutorial/

I don't have the exact code you will need for your custom walker, but this should be the correct way to approach what you're trying to do at least! :)

Specifically, you would probably want to extend Walker_Comment with your own class to override the "paged_walk" method of the class, which is what is used in wp_list_comments: http://core.trac.wordpress.org/browser/trunk/wp-includes/class-wp-walker.php#L260

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.