Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get comment pages count

This page is marked as incomplete. You can help Codex by expanding it.


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); ?>


(array) (optional) array of comment objects. If empty, $wp_query->comments will be used.
Default: null
(integer) (optional) comments per page.
Default: null
(boolean) (optional) control over flat or threaded comments.
Default: null

Return Values

Number of comment pages.


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 );


  • Typically you cannot use this function before the The Loop has started.

Change Log

Since: 2.7.0

Source File

get_comment_pages_count() is located in wp-includes/comment.php.


See also index of Function Reference and index of Template Tags.