get_comment_pages_count()
Calculate the total number of comment pages.
No Hooks.
Return
Int
. Number of comment pages.
Usage
get_comment_pages_count( $comments, $per_page, $threaded );
- $comments(WP_Comment[])
- Array of WP_Comment objects.
Default: $wp_query->comments - $per_page(int)
- Comments per page.
Default: value of comments_per_page query var, option of the same name, or 1 (in that order) - $threaded(true|false)
- Control over flat or threaded comments.
Default: value of thread_comments option
Examples
#1 Example of using a function in the loop:
$pages = get_comment_pages_count();
#2 Example of using custom parameters
The example above uses all default values, which are taken from the settings. And this example shows how its parameters work:
// pages of comments if 25 comments per page. $pages = get_comment_pages_count( null, 25 ); // comment pages if you do not divide comments into tree-like type (thread comments). $pages = get_comment_pages_count( null, null, false ); // pages of comments, if 10 per page and they are tree-like (thread comments). $pages = get_comment_pages_count( null, 10, true );
#3 Using a function outside the comment loop
If the function is used outside the comment loop, you need to specify the $comments parameter, which contains an array of comments to be counted. Such an array can be obtained by necessary arguments, using class: WP_Comment_Query{}.
Get comments on the parameters you want and find out how many pages they break down into:
$args = array( // query args here ); $comments_query = new WP_Comment_Query; $comments = $comments_query->query( $args ); $pages = get_comment_pages_count( $comments );
Notes
- Global. WP_Query. $wp_query WordPress Query object.
Changelog
Since 2.7.0 | Introduced. |