• 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

Blog Template & excluding categories

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 › Blog Template & excluding categories

This topic is: not resolved

Tagged: blog template, excluding categories

  • This topic has 7 replies, 3 voices, and was last updated 10 years, 5 months ago by LoriSm.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • December 6, 2014 at 7:07 am #133795
    luba lee
    Participant

    Hello all,

    I wanted to exclude a category from the blog page, and I made it like this: going to theme config, blog template and puting the ID of the category I wanted excluded.

    For some reason I don't get, it didn't work. I tried with the blog having the blog template, and without that template (default template), but nothing.

    This is how it worked:

    /** Exclude certain category from posts */
    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', '-156' );
    }
    }

    But I wanted to understand what exactly the blog template is for, and how come it didn't work from the configuration?

    December 6, 2014 at 8:11 am #133805
    Ren Ventura
    Member

    Try this:

    https://gist.github.com/EngageWP/a4696c3c3ddb829bb42d#file-remove-categories-blog-index-php


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

    December 6, 2014 at 8:27 am #133808
    luba lee
    Participant

    Yes, thank you @Ren, that's a similar code, and it worked, but I wanted to know why it didn't work the other way, from the configuration 🙂

    And I wanted to understand what exactly the blog template is for.

    December 6, 2014 at 8:35 am #133810
    Ren Ventura
    Member

    The reason it didn't work when you were using the blog template is because the blog template does not use the main query. Therefore, trying to customize the main query on the blog template won't work. Here's a helpful post from Bill Erickson that goes into detail.

    http://www.billerickson.net/dont-use-genesis-blog-template/


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

    December 6, 2014 at 8:43 am #133813
    luba lee
    Participant

    Yes, I've read this post before (it's a bit tricky for me, maybe because english is not my mother tongue).

    The thing is I tried it also without the blog template (using the default template), but didn't work either.

    Thank you for being so patient, Ren 😉

    December 6, 2014 at 9:01 am #133815
    Ren Ventura
    Member

    You're welcome! You were using add_action when you should have been using add_filter since you were modifying the query.


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

    December 6, 2014 at 12:02 pm #133834
    luba lee
    Participant

    Thank you, Ren. I'm reading the article all over again 🙂

    January 22, 2015 at 12:25 am #138243
    LoriSm
    Member

    This worked great for me thanks!!

  • Author
    Posts
Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘General Discussion’ 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

© 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