-
-
Save 5ally/c76588e33f44d3281c34ea9039a94859 to your computer and use it in GitHub Desktop.
Using a modified pagination function. See https://stackoverflow.com/q/58709835 for details.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // You should place this file in your-theme/inc | |
/** | |
* Pagination layout. | |
* | |
* @package understrap | |
*/ | |
// Exit if accessed directly. | |
defined( 'ABSPATH' ) || exit; | |
if ( ! function_exists( 'understrap_pagination' ) ) { | |
function understrap_pagination( $args = array(), $class = 'pagination' ) { | |
$args = wp_parse_args( | |
$args, | |
array( | |
'mid_size' => 2, | |
'prev_next' => true, | |
'prev_text' => __( '«', 'understrap' ), | |
'next_text' => __( '»', 'understrap' ), | |
'screen_reader_text' => __( 'Posts navigation', 'understrap' ), | |
'type' => 'array', | |
'current' => max( 1, get_query_var( 'paged' ) ), | |
'total' => $GLOBALS['wp_query']->max_num_pages, | |
) | |
); | |
// Nothing to paginate, so let's bail. | |
if ( ! $links = paginate_links( $args ) ) { | |
return; | |
} | |
?> | |
<nav aria-label="<?php echo $args['screen_reader_text']; ?>"> | |
<ul class="pagination"> | |
<?php | |
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 | |
} | |
?> | |
</ul> | |
</nav> | |
<?php | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Template Name: Test */ | |
?> | |
<!-- Add other markup as necessary.. --> | |
<?php get_header(); ?> | |
<div class="bg-light"> | |
<div class="container space-top-3 space-bottom-2"> | |
<div class="row"> | |
<?php | |
$paged = max( get_query_var( 'paged' ), get_query_var( 'page' ), 1 ); | |
$args = array( | |
'post_type' => 'post', | |
'orderby' => 'post_date', | |
'order' => 'desc', | |
'perm' => 'readable', | |
'show_post_views' => true, | |
'posts_per_page' => 9, | |
'paged' => $paged | |
); | |
$latestArticles = new WP_Query( $args ); | |
if ( $latestArticles->have_posts() ) : | |
while ( $latestArticles->have_posts() ) : $latestArticles->the_post(); | |
get_template_part( 'loop-templates/content-search', get_post_format() ); | |
endwhile; | |
?> | |
</div> | |
<div class="row mt-3"> | |
<div class="col-auto"> | |
<?php | |
understrap_pagination( [ | |
'current' => $paged, | |
'total' => $latestArticles->max_num_pages, | |
] ); | |
?> | |
</div> | |
</div> | |
<?php wp_reset_postdata(); ?> | |
<?php else : ?> | |
<!-- do nothing --> | |
<?php endif; ?> | |
</div> | |
</div> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment