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