Advertisements

get_comment_pages_count

Definition:
function get_comment_pages_count( $comments = null, $per_page = null, $threaded = null ) {}

Calculate the total number of comment pages.

Parameters

  • array $comments: Optional array of comment objects. Defaults to $wp_query->comments
  • int $per_page: Optional comments per page.
  • boolean $threaded: Optional control over flat or threaded comments.

Return values

returns:Number of comment pages.

Source code

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) )

		$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;

}

1324

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: