Hi @corpsehands!
Pagination can be a bit complex at times, yes. Before we dive into that, I’d like to offer another suggestion for reversing your post order. At the moment you’re using a URL based solution – if you wanted, you could add something like this in your child theme’s functions.php
file:
// Reverse post order
function reverse_my_posts( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
$query->set( 'order', 'ASC' );
}
}
add_filter( 'pre_get_posts', 'reverse_my_posts' );
That would reverse the order of posts without your URL needing to have ?order=asc
on the end ??
Now, for the pagination issue. Here’s what’s happening and why (if you’d rather not go through the background, feel free to skip ahead!)
The functions WordPress uses are next_posts_link()
and previous_posts_link()
The words next and previous refer to the next/previous group of posts – they aren’t tied to any specific chronological order.
WordPress’s default is newest first – so the “next” group of posts is actually older posts.
That makes sense to a blog, but not necessarily to the way most people think of the words next/previous.
To get around that many themes (including Illustratr) use the functions backwards – so on a standard blog, “Previous” actually means older posts, and “Next” actually means newer posts.
On your site, there’s an additional layer, because you’ve reversed the post order – so for you, the next group of posts is newer.
– Default WordPress function: “Next” is the next group (older posts)
– Illustratr’s usage: “Next” is the previous group (newer posts)
– Your setup: “Next” is the previous group (older posts)
Short version: Illustratr reverses things so they make more sense, but you’ve now reversed them again so they feel backwards.
Solution:
What we need to do no is un-reverse the functions, so that “next” leads to newer posts. Illustratr’s navigation function is pluggable – meaning we can replace it with our own version.
Paste this in your child theme’s functions.php
file:
// Reverse post pagination links
function illustratr_paging_nav( $max_num_pages = '' ) {
// Get max_num_pages if not provided
if ( '' == $max_num_pages ) {
$max_num_pages = $GLOBALS['wp_query']->max_num_pages;
}
// Don't print empty markup if there's only one page.
if ( $max_num_pages < 2 ) {
return;
}
?>
<nav class="navigation paging-navigation" role="navigation">
<h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'illustratr' ); ?></h1>
<div class="nav-links">
<?php if ( get_previous_posts_link( '', $max_num_pages ) ) : ?>
<div class="nav-previous"><?php previous_posts_link( __( '<span class="meta-nav">←</span> Previous', 'illustratr' ), $max_num_pages ); ?></div>
<?php endif; ?>
<?php if ( get_next_posts_link( '', $max_num_pages ) ) : ?>
<div class="nav-next"><?php next_posts_link( __( 'Next <span class="meta-nav">→</span>', 'illustratr' ), $max_num_pages ); ?></div>
<?php endif; ?>
</div><!-- .nav-links -->
</nav><!-- .navigation -->
<?php
}
With that version, your Next link on the right will lead to newer posts (since you’ve reversed the order).
Let me know how the above goes! ??