get_comment_pages_count()
最后更新于:2021-11-26 09:00:58
get_comment_pages_count( GC_Comment[]$comments=null, int$per_page=null, bool$threaded=null)Calculate the total number of comment pages.
参数
- $comments
-
(GC_Comment[]) (Optional) Array of GC_Comment objects. Defaults to
$gc_query->comments
.Default value: null
- $per_page
-
(int) (Optional) Comments per page.
Default value: null
- $threaded
-
(bool) (Optional) Control over flat or threaded comments.
Default value: null
响应
(int) Number of comment pages.
源文件
文件: gc-includes/comment.php
function get_comment_pages_count( $comments = null, $per_page = null, $threaded = null ) {
global $gc_query;
if ( null === $comments && null === $per_page && null === $threaded && ! empty( $gc_query->max_num_comment_pages ) ) {
return $gc_query->max_num_comment_pages;
}
if ( ( ! $comments || ! is_array( $comments ) ) && ! empty( $gc_query->comments ) ) {
$comments = $gc_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;
}