dozent_pagination( int $total_count, int $per_page, int $current_page, null $singular_text = null, null $plural_text = null, bool $echo = true )

Generate the pagination


Description

See also


Parameters

$total_count

(int) (Required)

$per_page

(int) (Required)

$current_page

(int) (Required)

$singular_text

(null) (Optional)

Default value: null

$plural_text

(null) (Optional)

Default value: null

$echo

(bool) (Optional)

Default value: true


Return

(mixed|void)


Source

File: includes/template-functions.php

	function dozent_pagination(
		$total_count = 0,
		$per_page = 0,
		$current_page = 0,
		$singular_text = null,
		$plural_text = null,
		$echo = true
	) {

		global $wp_query;

		if ( ! $total_count ) {
			if ( ! empty( $wp_query->found_posts ) ) {
				$total_count = $wp_query->found_posts;
			}
		}

		//First get per page form the query
        //TODO: Should remove this commented block
        /*
		if ( ! $per_page && ! empty( $wp_query->query_vars[ 'posts_per_page' ] ) ) {
			$per_page = (int) $wp_query->query_vars[ 'posts_per_page' ];
		}
		*/

		//If not exists per page, then get it from the default option
		if ( ! $per_page ) {
			$per_page = dozent_show_per_page();
		}

		if ( ! $singular_text ) {
			$singular_text = __( 'item', 'dozent' );
		}

		if ( ! $plural_text ) {
			$plural_text = __( 'items', 'dozent' );
		}

		$current_page = $current_page ? $current_page : dozent_current_page();

		$from_num = ( $current_page - 1 ) * $per_page + 1;
		$to_num   = $from_num + $per_page - 1;

		if ( $to_num >= $total_count ) {
			$to_num = $total_count;
		}

		$defaults = apply_filters( 'dozent_pagination_args',
			[
				'per_page'      => $per_page,
				'current_page'  => $current_page,
				'total'         => $total_count,
				'singular_text' => $singular_text,
				'plural_text'   => $plural_text,
				'from_num'      => $from_num,
				'to_num'        => $to_num,
			]
		);

		extract( $defaults, EXTR_SKIP );

		ob_start();

		dozent_load_template( 'partial/pagination', $defaults );
		$output = apply_filters( 'partial/pagination', ob_get_clean() );

		if ( $echo ) {
			echo $output;
		}

		return $output;
	}


Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.