Comment paging and sorting from Viper007Bond. see #7927

git-svn-id: http://svn.automattic.com/wordpress/trunk@9296 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan
2008-10-23 16:08:47 +00:00
parent 93de637a55
commit 91841f2e3c
9 changed files with 131 additions and 21 deletions

View File

@@ -480,6 +480,45 @@ function &separate_comments(&$comments) {
return $comments_by_type;
}
/**
* Calculate the total number of comment pages.
*
* @since 2.7.0
*
* @param array $comments Optional array of comment objects. Defaults to $wp_query->comments
* @param int $per_page Optional comments per page.
* @param boolean $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 ( !$comments || !is_array($comments) )
$comments = $wp_query->comments;
if ( empty($comments) )
return 0;
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;
}
/**
* Does comment contain blacklisted characters or words.
*