ap_pagination( float $current = false, int $total = false, string $format = '?paged=%#%', string $page_num_link = false )

Description #

Anspress pagination Uses paginate_links.

Parameters #

  • $current
    float (Optional) Current paged, if not set then get_query_var('paged') is used. Default value: false
  • $total
    int (Optional) Total number of pages, if not set then global $questions is used. Default value: false
  • $format
    string (Optional) pagination format. Default value: '?paged=%#%'
  • $page_num_link
    string (Optional) Base link. Default value: false

Source #

File: includes/theme.php

function ap_pagination( $current = false, $total = false, $format = '?paged=%#%', $page_num_link = false ) {
	global $ap_max_num_pages, $ap_current;

	if ( is_front_page() ) {
		$format = '';
	}

	$big = 999999999; // Need an unlikely integer.

	if ( false === $current ) {
		$paged   = ap_sanitize_unslash( 'ap_paged', 'r', 1 );
		$current = is_front_page() ? max( 1, $paged ) : max( 1, get_query_var( 'paged' ) );
	} elseif ( ! empty( $ap_current ) ) {
		$current = $ap_current;
	}

	if ( ! empty( $ap_max_num_pages ) ) {
		$total = $ap_max_num_pages;
	} elseif ( false === $total && isset( anspress()->questions->max_num_pages ) ) {
		$total = anspress()->questions->max_num_pages;
	}

	if ( false === $page_num_link ) {
		$page_num_link = str_replace( array( '&', '&' ), '&', get_pagenum_link( $big ) );
	}

	$base = str_replace( $big, '%#%', $page_num_link );

	if ( 1 === $total ) {
		return;
	}

	echo '<div class="ap-pagination clearfix">';
	$links = paginate_links(
		array(
			'base'     => $base,
			'format'   => $format,
			'current'  => $current,
			'total'    => $total,
			'end_size' => 2,
			'mid_size' => 2,
		)
	);
	if ( $links ) {
		$links = str_replace( '<a class="next page-numbers"', '<a class="next page-numbers" rel="next"', $links );
		$links = str_replace( '<a class="prev page-numbers"', '<a class="prev page-numbers" rel="prev"', $links );
		echo wp_kses_post( $links );
	}
	echo '</div>';
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment