• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Exclude/include Categories in Previous/Next link navigation

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Exclude/include Categories in Previous/Next link navigation

This topic is: not resolved

Tagged: categories, next, previous

  • This topic has 5 replies, 3 voices, and was last updated 4 years, 6 months ago by dreamdancer.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • January 20, 2016 at 1:36 pm #177029
    dan121
    Member

    I have my blog divided into two parts using category pages.

    Using the custom field query_args, one page shows posts from one category, and the other page shows all the posts except for that one category.

    This works fine, but I've run into a problem with the previous/next navigation links at the end of the single entries: the navigation links ignore the categories.

    Navigation links are added with this in functions.php: add_action( 'genesis_entry_footer', 'genesis_prev_next_post_nav' );

    I need some way to limit the navigation links to a specific category on one set of posts, and to exclude that category on the other set of posts.

    For example, if I have categories of apples, oranges, grapes and automobiles:
    Category page Fruit shows all the fruit posts and excludes auto posts, and next/prev links only go to fruit posts.
    Category page Cars only shows auto posts, and next/prev links only go to auto posts.

    January 21, 2016 at 8:40 am #177078
    Brad Dalton
    Participant

    You'll need to use the parameters for the previous and next post functions.

    https://codex.wordpress.org/Function_Reference/previous_post_link
    https://codex.wordpress.org/Function_Reference/next_post_link


    Tutorials for StudioPress Themes & WooCommerce.

    January 21, 2016 at 4:09 pm #177116
    Brad Dalton
    Participant

    I think you mean in same term which is a paremater you can use in each function however you'll need to rebuild the function because there is no filter added to the genesis_prev_next_post_nav function in genesis.

    in_same_term
    (boolean) (optional) Indicates whether previous post must be within the same taxonomy term as the current post. If set to 'true', only posts from the current taxonomy term will be displayed. If the post is in both the parent and subcategory, or more than one term, the previous post link will lead to the previous post in any of those terms.
    true
    false


    Tutorials for StudioPress Themes & WooCommerce.

    January 25, 2016 at 8:00 am #177433
    dan121
    Member

    yeah, I had to ditch genesis_prev_next_post_nav function and use this code:

    add_action('genesis_entry_footer', 'custom_pagination_links', 15 );
    function custom_pagination_links() {
    if( !is_single() ) 
          return;
    ?>
    <div id="prev-next">
    <?php
        previous_post_link( '<div class="prev-link">&larr; Previous<br />%link</div>', '%title', TRUE );
        next_post_link( '<div class="next-link">Next &rarr;<br />%link</div>', '%title', TRUE );
    ?></div>
    <?php
    }
    January 25, 2016 at 12:02 pm #177470
    Brad Dalton
    Participant

    Thats it!


    Tutorials for StudioPress Themes & WooCommerce.

    February 26, 2019 at 4:41 pm #489735
    dreamdancer
    Participant

    I have been looking all over for how to do this. Thanks so much!!!

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble