get_comment_pages_count
函数
get_comment_pages_count ( $comments = null, $per_page = null, $threaded = null )
- 参数
-
-
(WP_Comment[])
$comments
Optional. Array of WP_Comment objects. Defaults to `$wp_query->comments`.- Required: 否
- Default: null
-
(int)
$per_page
Optional. Comments per page.- Required: 否
- Default: null
-
(bool)
$threaded
Optional. Control over flat or threaded comments.- Required: 否
- Default: null
-
(WP_Comment[])
- 返回值
-
- (int) Number of comment pages.
- 定义位置
-
-
wp-includes/comment.php
, line 992
-
wp-includes/comment.php
- 引入
- 2.7.0
- 弃用
- –
Calculates the total 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;
}
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;
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。