Codex tools: Log in
Calculate the total number of comment pages.
This function lets you calculate how many pages of comments there will be for a post, given the number of comments to show per page, and whether the comments should be threaded or not.
<?php get_comment_pages_count( $comments, $per_page, $threaded); ?>
This function can be used within the loop like this:
$pages = get_comment_pages_count();
This will use the defaults for the number of comments per page and threading. You can use custom values like this:
// Show 25 comments per page. $pages = get_comment_pages_count( null, 25 ); // Don't thread comments. $pages = get_comment_pages_count( null, null, false ); // Show 10 comments per page, use threading. $pages = get_comment_pages_count( null, 10, true );
When inside the loop, you can just pass null as the value for the $comment parameter, as shown above. You can also use the function outside the loop, but you need to pass in the array of comments. For example, you may perform a custom comment query using WP_Comment_Query:
$args = array( // query args here ); $comments_query = new WP_Comment_Query; $comments = $comments_query->query( $args ); $pages = get_comment_pages_count( $comments );
get_comment_pages_count() is located in