get_comment_pages_count()
get_comment_pages_count( WP_Comment[] $comments = null,…
get_comment_pages_count( WP_Comment[] $comments = null, int $per_page = null, bool $threaded = null )
计算评论页的总数。
Calculate the total number of comment pages.
计算评论页的总数。
Calculate the total number of comment pages.
目录锚点:#参数#返回#源码#笔记
参数(Parameters)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| $comments | (WP_Comment[]) | 可选 | WP_Comment对象的数组。默认为$wp_query->comments。 |
| $per_page | (int) | 可选 | 每页评论。 |
| $threaded | (bool) | 可选 | 控制平面或线程注释。 |
返回(Return)
(int)评论页数。
源码(Source)
/**
* Calculate the total number of comment pages.
*
* @since 2.7.0
*
* @uses Walker_Comment
*
* @global WP_Query $wp_query
*
* @param array $comments Optional array of 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;
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;
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.7.0 | wp-includes/comment.php:985 | 5 | 3 |
笔记(Notes)
基本用法
每页评论数
圈外
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!