I have been debugging this but I cannot seem to find what's wrong. An extra eye would help! I am trying to add pagination on my blog posts. Here is the code
On home.php
<?php
$total_pages = $wp_query->max_num_pages;
if ( $total_pages > 1 ) : ?>
<div class="pagination col-12 text-center mt-3">
<?php the_posts_navigation(); ?>
</div>
<?php endif; ?>
And on template-tags.php
if ( ! function_exists( 'the_posts_navigation' ) ) :
function the_posts_navigation() {
global $wp_query;
echo paginate_links( array(
'base' => get_permalink() . 'page/%#%' . '/', 'format' => '?paged=%#%',
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'prev_text' => return_svg( 'arrow-left' ),
'next_text' => return_svg( 'arrow-right' ),
) );
}
endif;
Any idea what seems to be wrong? Thank you so much!
home.php
template? 2) Ontemplate-tags.php
you check if the_post_navigation exists, but it always exists, because it's wordpress function. Do you call it if it exists?home.php
. I am trying to make global pagination. What would you suggest? Even if I remove the if exists condition, pagination won't still show.home.php
is automatically used on the posts page. This is my reference: wphierarchy.com @anton, I still cannot see why the pagination is not showing. Blogs are showing though. Something wrong with myif
statement on displaying pagination?