get_comment_pages_count
Calculate the total number of comment pages.
Description
(int) get_comment_pages_count( (constant) $comments = null, (constant) $per_page = null, (null) $threaded = null );
Returns (int)
Number of comment pages.
Parameters (3)
- 0. $comments — Optional. (constant) =>
null
- Array of
WP_Comment
objects. Defaults to$
->commentswp_query
- 1. $per_page — Optional. (constant) =>
null
- Comments per page.
- 2. $threaded — Optional. (null) =>
null
- Control over flat or threaded comments.
Usage
if ( !function_exists( 'get_comment_pages_count' ) ) { require_once ABSPATH . WPINC . '/comment.php'; } // Optional array of WP_Comment objects. Defaults to $wp_query->comments $comments = null; // Optional comments per page. $per_page = null; // Optional control over flat or threaded comments. $threaded = null; // NOTICE! Understand what this does before running. $result = get_comment_pages_count($comments, $per_page, $threaded);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/comment.php
- function get_comment_pages_count( $comments = null, $per_page = null, $threaded = null ) {
- global $wp_query;
- if ( null === $comments && null === $per_page && null === $threaded && !empty($wp_query->max_num_comment_pages) )
- return $wp_query->max_num_comment_pages;
- if ( ( ! $comments || ! is_array( $comments ) ) && ! empty( $wp_query->comments ) )
- $comments = $wp_query->comments;
- if ( empty($comments) )
- return 0;
- if ( ! get_option( 'page_comments' ) ) {
- return 1;
- }
- if ( !isset($per_page) )
- $per_page = (int) get_query_var('comments_per_page');
- if ( 0 === $per_page )
- $per_page = (int) get_option('comments_per_page');
- if ( 0 === $per_page )
- return 1;
- if ( !isset($threaded) )
- $threaded = get_option('thread_comments');
- if ( $threaded ) {
- $walker = new Walker_Comment;
- $count = ceil( $walker->get_number_of_root_elements( $comments ) / $per_page );
- } else {
- $count = ceil( count( $comments ) / $per_page );
- }
- return $count;
- }