2016-11-23 09:42:53 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2019-11-14 17:16:31 +00:00
|
|
|
* Pagination layout
|
2016-11-23 09:42:53 +00:00
|
|
|
*
|
|
|
|
* @package understrap
|
|
|
|
*/
|
|
|
|
|
2019-06-20 08:57:12 +00:00
|
|
|
// Exit if accessed directly.
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
2018-09-10 21:59:04 +00:00
|
|
|
|
2018-11-18 23:37:12 +00:00
|
|
|
if ( ! function_exists( 'understrap_pagination' ) ) {
|
2019-12-14 08:19:36 +00:00
|
|
|
/**
|
|
|
|
* Displays the navigation to next/previous set of posts.
|
|
|
|
*
|
|
|
|
* @param string|array $args {
|
|
|
|
* (Optional) Array of arguments for generating paginated links for archives.
|
|
|
|
*
|
|
|
|
* @type string $base Base of the paginated url. Default empty.
|
|
|
|
* @type string $format Format for the pagination structure. Default empty.
|
|
|
|
* @type int $total The total amount of pages. Default is the value WP_Query's
|
|
|
|
* `max_num_pages` or 1.
|
|
|
|
* @type int $current The current page number. Default is 'paged' query var or 1.
|
|
|
|
* @type string $aria_current The value for the aria-current attribute. Possible values are 'page',
|
|
|
|
* 'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.
|
|
|
|
* @type bool $show_all Whether to show all pages. Default false.
|
|
|
|
* @type int $end_size How many numbers on either the start and the end list edges.
|
|
|
|
* Default 1.
|
|
|
|
* @type int $mid_size How many numbers to either side of the current pages. Default 2.
|
|
|
|
* @type bool $prev_next Whether to include the previous and next links in the list. Default true.
|
|
|
|
* @type bool $prev_text The previous page text. Default '«'.
|
|
|
|
* @type bool $next_text The next page text. Default '»'.
|
|
|
|
* @type string $type Controls format of the returned value. Possible values are 'plain',
|
|
|
|
* 'array' and 'list'. Default is 'array'.
|
|
|
|
* @type array $add_args An array of query args to add. Default false.
|
|
|
|
* @type string $add_fragment A string to append to each link. Default empty.
|
|
|
|
* @type string $before_page_number A string to appear before the page number. Default empty.
|
|
|
|
* @type string $after_page_number A string to append after the page number. Default empty.
|
|
|
|
* @type string $screen_reader_text Screen reader text for the nav element. Default 'Posts navigation'.
|
|
|
|
* }
|
|
|
|
* @param string $class (Optional) Classes to be added to the <ul> element. Default 'pagination'.
|
|
|
|
*/
|
2018-07-12 19:07:38 +00:00
|
|
|
function understrap_pagination( $args = array(), $class = 'pagination' ) {
|
2018-05-11 19:28:07 +00:00
|
|
|
|
2019-12-14 11:00:39 +00:00
|
|
|
if ( ! isset( $args['total'] ) && $GLOBALS['wp_query']->max_num_pages <= 1 ) {
|
2018-11-18 23:37:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-05-11 19:28:07 +00:00
|
|
|
|
2018-11-18 23:37:12 +00:00
|
|
|
$args = wp_parse_args(
|
|
|
|
$args,
|
|
|
|
array(
|
|
|
|
'mid_size' => 2,
|
|
|
|
'prev_next' => true,
|
|
|
|
'prev_text' => __( '«', 'understrap' ),
|
|
|
|
'next_text' => __( '»', 'understrap' ),
|
|
|
|
'type' => 'array',
|
|
|
|
'current' => max( 1, get_query_var( 'paged' ) ),
|
2019-12-14 08:19:36 +00:00
|
|
|
'screen_reader_text' => __( 'Posts navigation', 'understrap' ),
|
2018-11-18 23:37:12 +00:00
|
|
|
)
|
|
|
|
);
|
2018-05-11 19:28:07 +00:00
|
|
|
|
2018-11-18 23:37:12 +00:00
|
|
|
$links = paginate_links( $args );
|
2019-12-14 11:00:39 +00:00
|
|
|
if ( ! $links ) {
|
|
|
|
return;
|
|
|
|
}
|
2018-05-11 19:28:07 +00:00
|
|
|
|
2018-11-18 23:37:12 +00:00
|
|
|
?>
|
2018-05-11 19:28:07 +00:00
|
|
|
|
2019-12-14 07:29:21 +00:00
|
|
|
<nav aria-labelledby="posts-nav-label">
|
|
|
|
|
|
|
|
<h2 id="posts-nav-label" class="sr-only">
|
|
|
|
<?php echo esc_html( $args['screen_reader_text'] ); ?>
|
|
|
|
</h2>
|
2018-05-11 19:28:07 +00:00
|
|
|
|
2019-12-14 07:26:31 +00:00
|
|
|
<ul class="<?php echo esc_attr( $class ); ?>">
|
2018-05-11 19:28:07 +00:00
|
|
|
|
2018-11-18 23:37:12 +00:00
|
|
|
<?php
|
|
|
|
foreach ( $links as $key => $link ) {
|
|
|
|
?>
|
|
|
|
<li class="page-item <?php echo strpos( $link, 'current' ) ? 'active' : ''; ?>">
|
|
|
|
<?php echo str_replace( 'page-numbers', 'page-link', $link ); ?>
|
|
|
|
</li>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
?>
|
2018-05-11 19:28:07 +00:00
|
|
|
|
2018-11-18 23:37:12 +00:00
|
|
|
</ul>
|
2018-05-11 19:28:07 +00:00
|
|
|
|
2018-11-18 23:37:12 +00:00
|
|
|
</nav>
|
2018-05-11 19:28:07 +00:00
|
|
|
|
2018-11-18 23:37:12 +00:00
|
|
|
<?php
|
|
|
|
}
|
2018-05-05 08:09:27 +00:00
|
|
|
}
|