Summery Summery
Calculate the total number of comment pages.
Syntax Syntax
Parameters Parameters
- $comments
-
(Optional) Array of WP_Comment objects. Defaults to $wp_query->comments.
Default value: null
- $per_page
-
(Optional) Comments per page.
Default value: null
- $threaded
-
(Optional) Control over flat or threaded comments.
Default value: null
Return Return
(int) Number of comment pages.
Source Source
File: wp-includes/comment.php
if ( empty( $type ) ) {
$type = 'comment';
}
$comments_by_type[ $type ][] = &$comments[ $i ];
if ( 'trackback' === $type || 'pingback' === $type ) {
$comments_by_type['pings'][] = &$comments[ $i ];
}
}
return $comments_by_type;
}
/**
* Calculate the total number of comment pages.
*
* @since 2.7.0
*
* @uses Walker_Comment
*
* @global WP_Query $wp_query WordPress Query object.
*
* @param WP_Comment[] $comments Optional. Array of WP_Comment objects. Defaults to `$wp_query->comments`.
* @param int $per_page Optional. Comments per page.
* @param bool $threaded Optional. Control over flat or threaded comments.
* @return int Number of comment pages.
*/
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;
Advertisement
Changelog Changelog
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |