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.

If we set wp to break comments into pages after X nr of comments and we have X+1 comments , wp only shows that last comment instead of showing X and move the comment from bottom onto the next page. Any help would be appreciated since it is a big deal for what I am trying to use it.

share|improve this question
1  
Which theme are you using? –  dalbaeb May 8 '13 at 16:31
    
I am using a theme made by me completely. Why? –  Strasbourg May 8 '13 at 19:10
add comment

2 Answers

up vote 1 down vote accepted

ok.. so I did it like this. Maybe will help some. Used the code from Last comment page first with full number of comments? but altered it a bit to fit my needs. So this goes into your template page where you call the comments (or you can wrap it in a function and put it into functions.php)

 <?php comments_template( '', true ); ?>
 <?php 
 $comments_to_display = get_comments(array('post_id' => get_the_ID()));
 $comments_per_page = 10; // MAYBE: use get_option()?
 $comment_page = get_query_var( 'cpage' );
 $comment_this_page_start = 0;
 $comment_this_page_count = $comments_per_page;
 $oldest_comment_page_count = count( $comments_to_display ) % $comments_per_page;
 if ( 0 == $oldest_comment_page_count ) {
 $oldest_comment_page_count = $comments_per_page;
 }
 if ( 1 == $comment_page ) {
$comment_this_page_count = $oldest_comment_page_count;
 } else {
$comment_this_page_start = $oldest_comment_page_count + ($comment_page - 2) * 
$comments_per_page;
}
$comments_to_display = array_slice( $comments_to_display, $comment_this_page_start,  
$comment_this_page_count );

wp_list_comments(array('style' => 'div'), $comments_to_display); ?>

You are now ready to rock and roll!

Later that day:

I tried to use this method with the ajax comment loading plugin and did not work like I wanted; I got rid of it for the moment. ( there's a problem with a parameter; basically if you set $comments_per_page to 10 it displays the first 10 comments of the day, then waits for the comments to reach to 20 in order to show the next 10.. then waits for comments to get to 30 to display the comments from 20 to 30. The issue seems to be simple and maybe someone will fix it in the future.)

So returning to my the solution I've added the following:

 $comments = array_reverse($comments);

in comments.php (theme dir), unchecked break comments into pages in admin panel and added:

 'per_page' => '100'  

as a paramater to wp_list_comments().

Now I always have the most recent 100 comments displayed without beggining a new page everytime the comment mark reaches to 101.

It simply pushes the older comment onto the next page and adds the newer at the top! It is more simple and less headache so I recommend the second solution!

share|improve this answer
add comment

In wp-admin, go to Settings -> Discussion -> Break comments into pages with X top level comments per page and the FIRST page displayed by default.

If you pick the first page displayed by default make sure the drop-down underneath is set to OLDER comments at the top of each page.

share|improve this answer
    
I've found the solution but I have to wait one more h to post it. What are you saying does not fit my needs. Lets say I set it to break into pages after 50 comments. Then if I have 51 comments and set show the recent comments at the top wp will only show 1 comment instead of showing me last 50 and have the first one posted moved into the next page. Check in about 1 hour to see my solution. –  Strasbourg May 8 '13 at 22:35
    
@Strasbourg I'm glad you found a way, though what I described works well on my local setup, and does not behave as you're describing in your comment. –  dalbaeb May 8 '13 at 23:37
    
Well it behaves if you select last page displayed by default with newer comments at the top of each page. If it doesnt please elaborate how you call the comments in your page template. Thank you! –  Strasbourg May 9 '13 at 0:56
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.