• 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 blog category from single post 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 › General Discussion › Exclude blog category from single post navigation

This topic is: resolved

Tagged: post navigation category exclude

  • This topic has 11 replies, 3 voices, and was last updated 10 years, 10 months ago by Brad Dalton.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • August 22, 2014 at 8:19 am #120472
    carrieoke13
    Participant

    Hi,
    Is there a way to exclude a blog category from single post navigation (previous/next buttons at the bottom of the post)?

    Thanks!

    http://mylifeinknitwear.com
    August 22, 2014 at 8:55 am #120476
    carrieoke13
    Participant

    I'm adding some more info in case it is helpful.

    I'm already excluding this category from the blog page using this code:

    
    /** Exclude certain category from blog page */
    
    add_action( 'pre_get_posts', 'be_exclude_category_from_blog' );
    
    function be_exclude_category_from_blog( $query ) {
    
        if( $query->is_main_query() && $query->is_home() ) {
    
            $query->set( 'cat', '-44' );
    
        }
    
    }
    

    but I'd like for it not to appear in the previous/post nav, or the monthly archive pages. I basically want the whole category to be separate from the blog.

    August 22, 2014 at 10:02 am #120488
    Ren Ventura
    Member

    If you're trying to keep eveything in this category separate, perhaps a custom post type might be ideal. Just a suggestion.

    This should do the trick, though:

    remove_action( 'genesis_entry_footer', 'genesis_prev_next_post_nav' );

    http://my.studiopress.com/snippets/entry-content/


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

    August 22, 2014 at 11:53 am #120514
    carrieoke13
    Participant

    Thanks, Ren. I thought a custom post type might be the better solution.

    If I was going to keep this as a blog category, are you saying I would put that snippet in my functions.php? how will it know which category to exclude? I want to keep the post navigation on regular posts.

    Thanks!

    August 22, 2014 at 12:11 pm #120519
    Ren Ventura
    Member

    Yes, it would go in your functions.php and you'd use it with the appropriate conditionals. For example:

    
    add_action( 'genesis_entry_footer', 'rv_remove_post_nav_cat', 999 );
    function rv_remove_post_nav_cat() {
    	if( has_category( 44 ) ) {
    		remove_action( 'genesis_entry_footer', 'genesis_prev_next_post_nav' );
    	}
    }
    

    You could also find where your child theme is adding the genesis_prev_next_post_nav and add if( !has_category( 44 ) ) to only add the single post navigation if the post does NOT have a category ID of 44. Personally, this is the route I'd take because it's cleaner.


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

    August 22, 2014 at 12:15 pm #120521
    carrieoke13
    Participant

    with the solutionn you're suggesting, post nav is removed from excluded categories, but those posts still remain in the navigation. as in, the post nav on the posts before and after the posts in those categories will still have navlinks pointing to those posts. (like, post 1 is in the blog category, post is in the patterns category, which is the one I want excluded. So Post 1 still has post nav, and the "next" link goes to Post 2.) so it isn't exactly accomplishing what I want because I don't want any links to the excluded posts to be on the post nav. am I understanding it wrong?

    August 22, 2014 at 12:32 pm #120522
    Ren Ventura
    Member

    I see what you're saying: you want to remove the posts completely from the entire post navigation rather than remove the post navigation from the posts. I haven't tested the code but that would be logical. You may want to go with a custom post type because this is breaking the flow of your normal blog posts and seems like a pretty big hack. If someone else can chime in with a solution I'm not thinking of, awesome. My suggestion, though, is to create a custom post type. Is this something you're comfortable doing?


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

    August 22, 2014 at 12:43 pm #120523
    Brad Dalton
    Participant

    Try the 4th parameter for both the next and previous post links

    excluded_terms
    (string/array) (optional) Array or a comma-separated list of numeric terms IDs from which the next post should not be listed. For example array(1, 5) or '1,5'. This argument used to accept a list of IDs separated by 'and', this was deprecated in WordPress 3.3
    Default: None

    <?php next_post_link( $format, $link, $in_same_term = false, 
    $excluded_terms = '', $taxonomy = 'category' ); ?>
    

    This is only the idea. The code will need to be written.


    Tutorials for StudioPress Themes.

    August 22, 2014 at 1:01 pm #120525
    carrieoke13
    Participant

    Okay I'm trying this:

    /*add previous and next post links*/
    add_action( 'genesis_entry_footer', 'custom_single_post_nav', 12 );
    /**
     * @author    Brad Dalton
     * @example   http://wpsites.net/web-design/different-ways-to-add-post-navigation-pagination-in-genesis/
     * @copyright 2014 WP Sites
     */
    function custom_single_post_nav() {
     
    	if ( ! is_singular( 'post' ) )
    		return;
     
    	echo '<div class="pagination-previous alignleft">';
    echo '<<';
    	previous_post_link('%link', ' %title', FALSE, '44');
    	echo '</div>';
    	
    	echo '<div class="pagination-next alignright">';
    
    	next_post_link('%link', '%title ', FALSE, '44');
    	echo '>>';
    	echo '</div>';
    
     
    }
    

    (which is your code for pagination, Brad!) and tried to add the parameter. It seems to be excluding the category; but it's doing something weird with the first post on the blog.

    So if you look, the default previous/next links are still showing on the blog: http://mylifeinknitwear.com/the-knit-generation/

    and the default nav is going to one post, the custom nav I added is going to a different post that is a couple of posts away.

    August 22, 2014 at 1:03 pm #120526
    carrieoke13
    Participant

    So I was wrong! I turned off the cache plugin and the right links are showing now!

    August 22, 2014 at 1:05 pm #120527
    carrieoke13
    Participant

    Aaaaand it's working!

    This post has one of the posts in the excluded category before it:

    http://mylifeinknitwear.com/sands-end/

    notice the difference in the two navs under the post.

    Thanks so much, Brad!

    August 22, 2014 at 1:08 pm #120528
    Brad Dalton
    Participant

    hahaha. Thanks for finding that code Carrie.


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘Exclude blog category from single post navigation’ is closed to new replies.

CTA

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

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 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