Add pluggable function wrappers to inc/pagination.php; add single quotes around active class name on line 41

This commit is contained in:
Alex Wright 2018-03-30 11:21:47 -05:00
parent 9397cfc53e
commit 8da32c1a75
1 changed files with 42 additions and 43 deletions

View File

@ -5,54 +5,53 @@
* @package understrap * @package understrap
*/ */
if ( ! function_exists( 'understrap_pagination' ) ) : if ( ! function_exists ( 'understrap_pagination' ) ) {
function understrap_pagination($args = [], $class = 'pagination') { function understrap_pagination($args = [], $class = 'pagination') {
if ($GLOBALS['wp_query']->max_num_pages <= 1) return; if ($GLOBALS['wp_query']->max_num_pages <= 1) return;
$args = wp_parse_args( $args, [ $args = wp_parse_args( $args, [
'mid_size' => 2, 'mid_size' => 2,
'prev_next' => false, 'prev_next' => false,
'prev_text' => __('&laquo;', 'understrap'), 'prev_text' => __('&laquo;', 'understrap'),
'next_text' => __('&raquo;', 'understrap'), 'next_text' => __('&raquo;', 'understrap'),
'screen_reader_text' => __('Posts navigation', 'understrap'), 'screen_reader_text' => __('Posts navigation', 'understrap'),
'type' => 'array', 'type' => 'array',
'current' => max( 1, get_query_var('paged') ), 'current' => max( 1, get_query_var('paged') ),
]); ]);
$links = paginate_links($args); $links = paginate_links($args);
$next_link = get_next_posts_page_link(); $next_link = get_next_posts_page_link();
$prev_link = get_previous_posts_page_link(); $prev_link = get_previous_posts_page_link();
?> ?>
<nav aria-label="<?php echo $args['screen_reader_text']; ?>"> <nav aria-label="<?php echo $args['screen_reader_text']; ?>">
<ul class="pagination"> <ul class="pagination">
<li class="page-item"> <li class="page-item">
<a class="page-link" href="<?php echo esc_attr($prev_link); ?>" aria-label="<?php echo __('Previous', 'understrap'); ?>"> <a class="page-link" href="<?php echo esc_attr($prev_link); ?>" aria-label="<?php echo __('Previous', 'understrap'); ?>">
<span aria-hidden="true"><?php echo esc_attr($args['prev_text']); ?></span> <span aria-hidden="true"><?php echo esc_attr($args['prev_text']); ?></span>
<span class="sr-only"><?php echo __('Previous', 'understrap'); ?></span> <span class="sr-only"><?php echo __('Previous', 'understrap'); ?></span>
</a> </a>
</li> </li>
<?php <?php
$i = 1; $i = 1;
foreach ( $links as $link ) { ?> foreach ( $links as $link ) { ?>
<li class="page-item <?php if ($i == $args['current']) { echo active; }; ?>"> <li class="page-item <?php if ($i == $args['current']) { echo 'active'; }; ?>">
<?php echo str_replace( 'page-numbers', 'page-link', $link ); ?> <?php echo str_replace( 'page-numbers', 'page-link', $link ); ?>
</li> </li>
<?php $i++;} ?> <?php $i++;} ?>
<li class="page-item"> <li class="page-item">
<a class="page-link" href="<?php echo esc_attr($next_link); ?>" aria-label="<?php echo __('Next', 'understrap'); ?>"> <a class="page-link" href="<?php echo esc_attr($next_link); ?>" aria-label="<?php echo __('Next', 'understrap'); ?>">
<span aria-hidden="true"><?php echo esc_attr($args['next_text']); ?></span> <span aria-hidden="true"><?php echo esc_attr($args['next_text']); ?></span>
<span class="sr-only"><?php echo __('Next', 'understrap'); ?></span> <span class="sr-only"><?php echo __('Next', 'understrap'); ?></span>
</a> </a>
</li> </li>
</ul> </ul>
</nav> </nav>
<?php <?php
} }
endif; }
?>