• 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

How to hide blog posts from a specific category on home page?

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 › How to hide blog posts from a specific category on home page?

This topic is: resolved

Tagged: category, design, filter, hide, homepage, index

  • This topic has 15 replies, 2 voices, and was last updated 12 years ago by maheshone.
Viewing 16 posts - 1 through 16 (of 16 total)
  • Author
    Posts
  • May 24, 2013 at 10:59 pm #42568
    maheshone
    Member

    Hi,

    Can anyone tell me how to hide blog posts from a specific category or categories on the home page?

    For example, My blog is http://www.minterest.com/ and on the homepage all you see is daily mashups so I want to hide all blog posts from the categoryhttp://www.minterest.com/category/minteresting/.

    ~ Mahesh


    Twitter — @maheshone
    Blog — http://www.minterest.com/
    vCard — http://www.maheshone.com/

    http://www.minterest.com/
    May 25, 2013 at 2:18 am #42577
    Brad Dalton
    Participant

    Try this http://www.studiopress.community/topic/hide-category-from-home-page/#post-36496


    Tutorials for StudioPress Themes.

    May 25, 2013 at 5:39 am #42582
    maheshone
    Member

    I must place the code
    <?php if ( is_home() ) { query_posts( 'cat=-1' ); } ?>

     

    here...
    `genesis_before` Hook
    This hook executes immediately after the opening `` tag.

     

    Right?


    Twitter — @maheshone
    Blog — http://www.minterest.com/
    vCard — http://www.maheshone.com/

    May 25, 2013 at 5:40 am #42583
    maheshone
    Member

    Hi Brad,

     

    I think it will solve my issue...  I want to try Option 2 (that's by using hooks).

    But can you please tell me which hook should I use?

    More specifically... where exactly should I place the code

    <?php if ( is_home() ) { query_posts( 'cat=-1' ); } ?>

    before the closing </head> tag, before the closing </body> tag, after the opening <body> tag. or somewhere else?

    Thanks!

     


    Twitter — @maheshone
    Blog — http://www.minterest.com/
    vCard — http://www.maheshone.com/

    May 26, 2013 at 1:48 pm #42707
    maheshone
    Member

    BUMP.... Can some one reply quickly? I'm still waiting...

     

    Please tell me which hook should I use?

    The following one?

    `genesis_before` Hook
    This hook executes immediately after the opening `` tag.


    Twitter — @maheshone
    Blog — http://www.minterest.com/
    vCard — http://www.maheshone.com/

    May 27, 2013 at 11:31 pm #42873
    maheshone
    Member

    Someone update this?


    Twitter — @maheshone
    Blog — http://www.minterest.com/
    vCard — http://www.maheshone.com/

    May 28, 2013 at 8:27 am #42909
    maheshone
    Member

    Hi there,

    I used the code "<?php if ( is_home() ) { query_posts( ‘cat=-1′ ); } ?>"

     

    And placed in the genesis_before Hook  and it says this hook executes immediately after the opening <body> tag.

    And I noticed that the blog posts from that particular category was not showing on the home page. But... I was unable to browse the pages... it was showing the homepage posts itself when I click on Page 2, 3, etc.


    Twitter — @maheshone
    Blog — http://www.minterest.com/
    vCard — http://www.maheshone.com/

    May 30, 2013 at 9:56 am #43218
    maheshone
    Member

    Can any one help? It's been several days and there's no support yet.


    Twitter — @maheshone
    Blog — http://www.minterest.com/
    vCard — http://www.maheshone.com/

    May 30, 2013 at 6:22 pm #43275
    Brad Dalton
    Participant

    Try the plugin which I linked to in that tutorial please.


    Tutorials for StudioPress Themes.

    May 30, 2013 at 9:29 pm #43295
    maheshone
    Member

    Yes, I'm now using a plugin temporarily... But I prefer to use a hook or coding manually... can you help that way? Or the hooks don't work?


    Twitter — @maheshone
    Blog — http://www.minterest.com/
    vCard — http://www.maheshone.com/

    May 30, 2013 at 9:57 pm #43305
    Brad Dalton
    Participant

    All the code in the tutorial provides different methods to hide specific categories from your home or blog page.

    You will need to modify the code with the category i.d's for your specific needs.

    The code I have provided is tested and works in your child themes functions.php file rather than Simple Hooks.


    Tutorials for StudioPress Themes.

    May 30, 2013 at 10:11 pm #43308
    maheshone
    Member

    Hi,

     

    I'm bad with coding... can anyone help me with this?

    I have pasted the child theme functions.php here

    https://docs.google.com/document/d/1fX_WQz_WSOwSH37Txmf4pLTyvMKslrQsnyFZaTaVQi4/edit [Anyone Can View & Edit This File]

    Can anyone place the necessary codes (pasted below) at the right place? I want to remove only one category.

    //Code for one category

    <?php if ( is_home() ) { query_posts( 'cat=-1' ); } ?>

    Twitter — @maheshone
    Blog — http://www.minterest.com/
    vCard — http://www.maheshone.com/

    May 30, 2013 at 10:28 pm #43309
    Brad Dalton
    Participant

    Try this http://www.studiopress.community/topic/hide-category-from-home-page/#post-43307


    Tutorials for StudioPress Themes.

    May 30, 2013 at 10:53 pm #43313
    maheshone
    Member

    Hi,

    I tried that and it gave the error...

    Parse error: syntax error, unexpected T_STRING in /home/interest/public_html/wp-content/themes/focus/functions.php on line 36

    I used the following code...

     

    /** Remove a category from home page*/
    add_action( 'pre_get_posts', 'remove_posts_in_category_on_blog' );
    function remove_posts_in_category_on_blog( $query ) {

    global $wp_the_query;
    if( $wp_the_query === $query && $query->is_home() ) {
    $query->set( 'cat', '-311' );
    }

    }


    Twitter — @maheshone
    Blog — http://www.minterest.com/
    vCard — http://www.maheshone.com/

    May 30, 2013 at 11:10 pm #43318
    Brad Dalton
    Participant

    Hello @maheshone

    Please copy the code using the view raw link and paste it at the end of your child themes functions.php file using a text editor like Notepad++.

    All my code works because its all tested.

    Just tested it again locally and it works without errors.

    Code not displaying? Grab it on Github.

    This code was tested on Genesis and excludes all posts from displaying on the home page which are in the category with i.d 18.

    You will need to change the 18 to your own category i.d.


    Tutorials for StudioPress Themes.

    May 30, 2013 at 11:26 pm #43320
    maheshone
    Member

    Finally, it worked!

     

    Thanks a ton! 🙂


    Twitter — @maheshone
    Blog — http://www.minterest.com/
    vCard — http://www.maheshone.com/

  • Author
    Posts
Viewing 16 posts - 1 through 16 (of 16 total)
  • The topic ‘How to hide blog posts from a specific category on home page?’ 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