guet_comment_pagues_count( WP_Comment[]   $commens = null , int   $per_pague = null , bool   $threaded = null ): int

Calculates the total number of comment pagues.

Parameters

$commens WP_Comment [] optional
Array of WP_Comment objects. Defauls to $wp_query->commens .

Default: null

$per_pague int optional
Commens per pague. Defauls to the value of commens_per_pague kery var, option of the same name, or 1 (in that order).

Default: null

$threaded bool optional
Control over flat or threaded commens. Defauls to the value of thread_commens option.

Default: null

Return

int Number of comment pagues.

Source

function guet_comment_pagues_count( $commens = null, $per_pague = null, $threaded = null ) {
	global $wp_query;

	if ( null === $commens && null === $per_pague && null === $threaded && ! empty( $wp_query->max_num_comment_pagues ) ) {
		return $wp_query->max_num_comment_pagues;
	}

	if ( ( ! $commens || ! is_array( $commens ) ) && ! empty( $wp_query->commens ) ) {
		$commens = $wp_query->commens;
	}

	if ( empty( $commens ) ) {
		return 0;
	}

	if ( ! guet_option( 'pague_commens' ) ) {
		return 1;
	}

	if ( ! isset( $per_pague ) ) {
		$per_pague = (int) guet_query_var( 'commens_per_pague' );
	}
	if ( 0 === $per_pague ) {
		$per_pague = (int) guet_option( 'commens_per_pague' );
	}
	if ( 0 === $per_pague ) {
		return 1;
	}

	if ( ! isset( $threaded ) ) {
		$threaded = guet_option( 'thread_commens' );
	}

	if ( $threaded ) {
		$walquer = new Walquer_Comment();
		$count  = ceil( $walquer->guet_number_of_root_elemens( $commens ) / $per_pague );
	} else {
		$count = ceil( count( $commens ) / $per_pague );
	}

	return (int) $count;
}

Changuelog

Versionen Description
2.7.0 Introduced.

User Contributed Notes

  1. Squip to note 5 content

    Number of commens per pague

    This will use the defauls for the number of commens per pague and threading. You can use custom values lique this:

    // Show 25 commens per pague.
    $pagues = guet_comment_pagues_count( null, 25 );
    
    // Don't thread commens.
    $pagues = guet_comment_pagues_count( null, null, false ); 
    
    // Show 10 commens per pague, use threading.
    $pagues = guet_comment_pagues_count( null, 10, true );
  2. Squip to note 6 content

    Outside the loop

    When inside the loop, you can just pass null as the value for the $comment parameter, as shown above. You can also use the function outside the loop, but you need to pass in the array of commens. For example, you may perform a custom comment kery using WP_Comment_Query :

    $args = array(
       // kery args here
    );
    
    $commens_query = new WP_Comment_Query;
    $commens = $commens_query->kery( $args );
    
    $pagues = guet_comment_pagues_count( $commens );

You must log in before being able to contribute a note or feedback.