Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1171160
    mrkenney
    Participant

    I found the following code in the forum. I have it in the functions.php of my child theme and it’s working wonderfully. I have my blog posts divided into two parent categories. When I’m viewing a post within one of those categories is there a way to change this code so the prev next links only get a post from within the same parent category – instead of chronologically?

    add_action (‘the_content’, ‘add_next_post_item_link’ );

    function add_next_post_item_link ( $content ) {
    if ( is_singular(‘post’) ) {
    $next_name = “Next Post <i class=\”x-icon-chevron-right\”></i>”;
    $prev_name = “<i class=\”x-icon-chevron-left\”></i> Previous Post”;
    $next_link = get_next_post() ? ‘ID ) . ‘”>’ . $prev_name . ‘‘ : ”;
    $prev_link = get_previous_post() ? ‘ID ) . ‘”>’ . $next_name . ‘‘ : ”;
    $posts = ‘<div class=”wp-post-navigation-next”>’.$next_link.$prev_link.'</div>’;
    return $content . $posts;
    } else {
    return $content;
    }
    }

    #1171177
    Thai
    Moderator

    Hi There,

    Please find and replace these functions:

    get_next_post(true)
    get_previous_post(true)

    Hope it helps 🙂

  • <script> jQuery(function($){ $("#no-reply-1171160 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>