-
-
Save 5ally/dbe0d17656afa8f67bbafb0d984dcbc2 to your computer and use it in GitHub Desktop.
Using the original 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 | |
/* 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 | |
$orig_max_num_pages = $wp_query->max_num_pages; // backup | |
// Change it just for the pagination. | |
// and $latestArticles is your custom WP_Query instance. | |
$wp_query->max_num_pages = $latestArticles->max_num_pages; | |
understrap_pagination( [ | |
'current' => $paged, | |
] ); | |
$wp_query->max_num_pages = $orig_max_num_pages; // restore | |
?> | |
</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