• I have no idea why this is so infuriatingly difficult to do, but I’m just trying to change the post navigation links and text so posts can be viewed chronologically without having to use a link that says “previous” to access what is chronologically after it & vice versa.

    here’s my site and the post page: https://www.arthuriansmutcycle.com/read/?order=asc

    as you can see, I have the posts set up to be viewed in ascending order. The links are still screwed up, though. I have a child theme already installed, I know code to adjust this belongs in function.php but I don’t know what the code is that I need for this (and googling didn’t help.)

    What I’m after is: the right hand link is just an arrow, and it takes you to the next page, the left hand link is an arrow that takes you to the previous page. That’s it. I could’ve fixed this in blogger in like 2 minutes, no idea why wordpress is like this.

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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">&larr;</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">&rarr;</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! ??

    Thread Starter corpsehands

    (@corpsehands)

    okay so, going to have to back up a bit here because i tried screwing around with the child theme and i completely broke my site and had to uninstall the theme and some plugins via FTP, so

    what’s the best child theme thing/plug-in whatever to be using? i had a “one click child theme” plug-in installed and when i tried creating a child theme, it broke the site. that’s all i did, i didn’t even try to do anything in the functions, it’s just completely died on me when i tried to create a child theme

    (also thank you for all this help!)

    Happy to help!

    I prefer creating a child theme manually, rather than relying on a plugin. There are functionality plugins you can use to drop code snippets into, and some people like using those:
    https://www.ads-software.com/plugins/functionality/
    and
    https://www.ads-software.com/plugins/code-snippets/
    are a couple I’ve seen.

    Personally, I’ve never had much success with those types of plugins – I usually end up having to fix the plugin/theme that gets generated manually, so it’s never been much of a time saver for me ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Changing Navigation Link & Text’ is closed to new replies.