本文整理汇总了PHP中Walker_Comment::get_number_of_root_elements方法的典型用法代码示例。如果您正苦于以下问题:PHP Walker_Comment::get_number_of_root_elements方法的具体用法?PHP Walker_Comment::get_number_of_root_elements怎么用?PHP Walker_Comment::get_number_of_root_elements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Walker_Comment
的用法示例。
在下文中一共展示了Walker_Comment::get_number_of_root_elements方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_comment_pages_count
/**
* 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 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;
}
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;
}