Update pagination.php

1. Dynamic prev and next
1. Improved active class
1. Improved ellipsis
This commit is contained in:
Johan Nielsen 2018-05-11 21:28:07 +02:00 committed by GitHub
parent e59538ad22
commit f8dd00d1c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 27 deletions

View File

@ -6,6 +6,7 @@
*/ */
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;
@ -25,19 +26,27 @@ if ( ! function_exists ( 'understrap_pagination' ) ) {
?> ?>
<nav aria-label="<?php echo $args['screen_reader_text']; ?>"> <nav aria-label="<?php echo $args['screen_reader_text']; ?>">
<ul class="pagination"> <ul class="pagination">
<?php <?php
$i = 1;
foreach ( $links as $link ) { ?> foreach ( $links as $key => $link ) { ?>
<li class="page-item <?php if ($i == $args['current']) { echo 'active'; }; ?>">
<li class="page-item <?php echo strpos( $link, 'current' ) ? 'active' : '' ?>">
<?php echo str_replace( 'page-numbers', 'page-link', $link ); ?> <?php echo str_replace( 'page-numbers', 'page-link', $link ); ?>
</li> </li>
<?php $i++;} ?> <?php } ?>
</ul> </ul>
</nav> </nav>
<?php <?php
} }
} }
?>