Answer the question
In order to leave comments, you need to log in
How to activate links for pagination?
now pagination is displayed, but after clicking on any of the pages it says page not found
<?php
if($query->max_num_pages == 1) {
echo '<span class="page-numbers current"></span>';
} else {
echo paginate_links( array(
'total' => $query->max_num_pages,
'prev_next' => '',
'next_text' => '',
) );
}
the_posts_pagination( array(
'paged' => get_query_var('paged')
));
?>
Answer the question
In order to leave comments, you need to log in
Try to display it like this: https://wp-kama.ru/function/the_posts_pagination .
Depends where you are. If this is any archive page (archive.php, category.php, home.php, etc.), then there is already a global request and there is wp_query()
NO NEED to call a custom instance . If you need to change the query, then you need to do it on the hook pre_get_posts
. For this, the existing query will work native functions for pagination the_posts_pagination()
and the_posts_navigation()
, I advise you to look at any popular or standard twenty theme as an example
. In rare cases, outside of archived pages, you may actually need to order from the record database and make pagination for them. Because I have already answered this question many times, then I wrote an article with a good working example , I recommend that you read
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question