Merge pull request #668 from 0dp/patch-3

dynamic prev_next
This commit is contained in:
Thomas A. Reinert 2018-05-11 23:57:31 +02:00 committed by GitHub
commit 1a5c667ae3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 41 deletions

View File

@ -6,13 +6,14 @@
*/
if ( ! function_exists ( 'understrap_pagination' ) ) {
function understrap_pagination($args = [], $class = 'pagination') {
if ($GLOBALS['wp_query']->max_num_pages <= 1) return;
$args = wp_parse_args( $args, [
'mid_size' => 2,
'prev_next' => false,
'prev_next' => true,
'prev_text' => __('&laquo;', 'understrap'),
'next_text' => __('&raquo;', 'understrap'),
'screen_reader_text' => __('Posts navigation', 'understrap'),
@ -21,37 +22,31 @@ 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;
foreach ( $links as $link ) { ?>
<li class="page-item <?php if ($i == $args['current']) { echo 'active'; }; ?>">
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 $i++;} ?>
<?php } ?>
<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
}
}
?>