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:
parent
b6867bf6f6
commit
e59538ad22
|
@ -12,7 +12,7 @@ if ( ! function_exists ( 'understrap_pagination' ) ) {
|
||||||
|
|
||||||
$args = wp_parse_args( $args, [
|
$args = wp_parse_args( $args, [
|
||||||
'mid_size' => 2,
|
'mid_size' => 2,
|
||||||
'prev_next' => false,
|
'prev_next' => true,
|
||||||
'prev_text' => __('«', 'understrap'),
|
'prev_text' => __('«', 'understrap'),
|
||||||
'next_text' => __('»', 'understrap'),
|
'next_text' => __('»', 'understrap'),
|
||||||
'screen_reader_text' => __('Posts navigation', 'understrap'),
|
'screen_reader_text' => __('Posts navigation', 'understrap'),
|
||||||
|
@ -21,19 +21,11 @@ if ( ! function_exists ( 'understrap_pagination' ) ) {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$links = paginate_links($args);
|
$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']; ?>">
|
<nav aria-label="<?php echo $args['screen_reader_text']; ?>">
|
||||||
<ul class="pagination">
|
<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
|
<?php
|
||||||
$i = 1;
|
$i = 1;
|
||||||
|
@ -44,12 +36,6 @@ if ( ! function_exists ( 'understrap_pagination' ) ) {
|
||||||
|
|
||||||
<?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>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<?php
|
<?php
|
||||||
|
|
Reference in New Issue