[Resolved] Behavior of Next/Previous Post links

Home Forums Support Behavior of Next/Previous Post links

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #884878
    Earl

    I’m not sure of the specific descriptive terminology, but below each post there are navigation links for the Category, next post and previous post, thus:

    https://www.dropbox.com/s/n6yhhx2rjc4n8af/nav_links.JPG

    Navigation links from post

    I’d like for the next/prev links to be limited in scope to the current post category. As it works now, if you continue following the chain of posts with either ‘next’ or ‘prev’ links you will exit the current category and go on to the next one.

    Is this an easy one?

    Thanks.

    #884910
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this PHP:

    add_filter( 'generate_category_post_navigation', '__return_true' );

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    Let me know πŸ™‚

    #885701
    Earl

    Tom –

    I just ran a quick test, and this seems to work fine.

    Thank you!!

    ESJ

    #885712
    Tom
    Lead Developer
    Lead Developer
    #920172
    phan cong tai

    Adding PHP:
    add_filter( 'generate_category_post_navigation', '__return_true' );
    where?

    My Custom Post Navigation code:

    <div id="post-nav">
    	<?php global $post;
        $prevPost = get_previous_post(false);
            if($prevPost) {
                $args = array(
                    'posts_per_page' => 1,
                    'include' => $prevPost->ID
                );
                $prevPost = get_posts($args);
                foreach ($prevPost as $post) {
                    setup_postdata($post);
        ?>
            <a class="post-previous" href="<?php the_permalink(); ?>">
    				<div class="post-nav-wrap" style="background: linear-gradient(0deg,rgba(52,62,71,0.1),rgba(52,62,71,0.3)),url('<?php the_post_thumbnail_url(); ?>');">
                <div class="post-nav">Previous</div>
                <h3 class="post-nav-title"><?php the_title(); ?></h3>
            </div></a>
        <?php
                    wp_reset_postdata();
                } //end foreach
            } // end if
             
            $nextPost = get_next_post(false);
            if($nextPost) {
                $args = array(
                    'posts_per_page' => 1,
                    'include' => $nextPost->ID
                );
                $nextPost = get_posts($args);
                foreach ($nextPost as $post) {
                    setup_postdata($post);
        ?>
            <a class="post-next" href="<?php the_permalink(); ?>">
            <div class="post-nav-wrap" style="background: linear-gradient(0deg,rgba(52,62,71,0.6),rgba(52,62,71,0.3)),url('<?php the_post_thumbnail_url(); ?>');">
                <h3 class="post-nav-title"><?php the_title(); ?></h3>
                <div class="post-nav">Next</div>					
            </div></a>
        <?php
                    wp_reset_postdata();
                } //end foreach
            } // end if
        ?>
    </div>
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.