dynamic prev_next

I've noticed that with the current implementation, next arrow is still shown if there are no more pages.
By setting prev_next to true, WordPress should handle the generation of next and previous arrows. 
This also means that the code is dramatically simplified.

But please test this, because I don't remember why I didn't write the code this way in the first place.
Maybe because there was some fringe case I tried to rectify?
This commit is contained in:
Johan Nielsen 2018-05-05 10:09:27 +02:00 committed by GitHub
parent b6867bf6f6
commit e59538ad22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 19 deletions

View File

@ -12,7 +12,7 @@ if ( ! function_exists ( 'understrap_pagination' ) ) {
$args = wp_parse_args( $args, [
'mid_size' => 2,
'prev_next' => false,
'prev_next' => true,
'prev_text' => __('«', 'understrap'),
'next_text' => __('»', 'understrap'),
'screen_reader_text' => __('Posts navigation', 'understrap'),
@ -21,37 +21,23 @@ if ( ! function_exists ( 'understrap_pagination' ) ) {
]);
$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>
<?php
$i = 1;
$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 ); ?>
<?php echo str_replace( 'page-numbers', 'page-link', $link ); ?>
</li>
<?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
}
}
}