0

I want to display threaded comments via ajax using pagination.

If I use this code to display comments for page 1 how can I know if there is something more to be displayed on page 2? If there is something I would display a link "get more comments" if not there will be no link.

$comments =     get_comments(array(
    'post_id' => $post_id,
    'status' => 'approve' 
));
    wp_list_comments(array(
        'page' => 1,
        'per_page' => 10,
        'avatar_size'   => 16,
    ), $comments);
1

Try get_comment_pages_count()?

<?php get_comment_pages_count( $comments, $per_page, $threaded); ?>

I'm guessing you're outside the loop, since you're calling get_comments(); in that case, you'll need to pass your $comments object:

$comments =     get_comments(array(
    'post_id' => $post_id,
    'status' => 'approve' 
));
wp_list_comments(array(
        'page' => 1,
        'per_page' => 10,
        'avatar_size'   => 16,
    ), $comments);

$comment_page_count = get_comment_pages_count( $comments );
  • Works smoothly. Thank you. Just a question why don't I have to use both arguments $per_page and $threaded. I tested it and it works ok with and without them. – Radek Oct 18 '13 at 2:08
  • You don't have to pass the $per_page and $threaded comments, because get_comment_pages_count() will use the default values. – Chip Bennett Oct 18 '13 at 11:25
  • That is the thing I don't understand. In my sample code above I overwrite the default values... – Radek Oct 19 '13 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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