• 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

Genesis loop for one category in home

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 › Genesis loop for one category in home

This topic is: not resolved

Tagged: loop

  • This topic has 8 replies, 2 voices, and was last updated 11 years, 4 months ago by marcello.vicidomini.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • March 16, 2014 at 12:30 pm #95173
    marcello.vicidomini
    Member

    Hi all,
    i'm trying to display a loop for just one category in the homepage. I've written a custom loop which is driving me a little bit crazy, since it seems to accept everything I define in the array except 'cat' (I'm sure i'm using the correct category ID, and I also tried with different IDs). So in spite of having

    'cat' => 29

    defined in the loop, all the categories keep appearing in the homepage 🙁

    What am I doing wrong?

    This is the code I have in my home.php file:

    remove_action( 'genesis_loop', 'genesis_do_loop' );
    add_action( 'genesis_loop', 'child_grid_loop_homepage' );
    function child_grid_loop_homepage() {
    	if ( function_exists( 'genesis_grid_loop' ) ) {
    		genesis_grid_loop( array(
    			'features' => 0,
    			'feature_image_size' => 0,
    			'feature_image_class' => 'alignleft post-image',
    			'feature_content_limit' => 200,
    			'grid_image_size' => 'homepage-featured-image',
    			'grid_image_class' => 'alignleft post-image',
    			'grid_content_limit' => 150,
    			'more' => __( '[Continue reading...]', 'genesis' ),
    			//* The next line is ignored and all the categories keep being included in the loop. Why?
    			'cat' => 29,
    			'post_per_page' => 6
    		) );
    	} else {
    		genesis_standard_loop();
    	}
    }

    Thanks a lot for your help! 😀

    March 16, 2014 at 3:44 pm #95205
    Brad Dalton
    Participant

    You can exclude categories using pre_get_posts


    Tutorials for StudioPress Themes.

    March 17, 2014 at 2:43 am #95256
    marcello.vicidomini
    Member

    Hello braddalton,

    thanks a lot for your answer!
    Don't you think that pre_get_posts would be impractical? It looks like each time you add a new category you have to edit the code. Or maybe I'm not getting something? Isn't there a way to include one category rather then excluding all the other ones?

    Thanks again for your help 😀

    March 17, 2014 at 3:16 am #95260
    Brad Dalton
    Participant

    Yes, you can see the examples on the Codex which you can include in the code.


    Tutorials for StudioPress Themes.

    March 19, 2014 at 6:05 am #95644
    marcello.vicidomini
    Member

    Hello Brad,
    I think I solved it, here's the code:

    if ( function_exists( 'genesis_grid_loop' ) ) {
    
    	//* Here's the line I added. I used the slug instead of the id, but if works with cat_ID too
    	query_posts('category_name=blog');
    
    	genesis_grid_loop( array(
    		'features' => 0,
    		'feature_image_size' => 0,
    		'feature_image_class' => 'alignleft post-image',
    		'feature_content_limit' => 200,
    		'grid_image_size' => 'homepage-featured-image',
    		'grid_image_class' => 'alignleft post-image',
    		'grid_content_limit' => 0,
    	) );
    } else {
    	genesis_standard_loop();
    }
    March 19, 2014 at 6:47 am #95651
    Brad Dalton
    Participant

    Never use query_posts http://en.wp.obenland.it/never-use-query-posts-again/


    Tutorials for StudioPress Themes.

    March 19, 2014 at 6:53 am #95653
    marcello.vicidomini
    Member

    Ok, that was clear 😀

    Should I use WP_Query instead?

    March 19, 2014 at 7:00 am #95655
    Brad Dalton
    Participant

    Why don't you simply display your category archive page on the front page?


    Tutorials for StudioPress Themes.

    March 19, 2014 at 7:06 am #95656
    marcello.vicidomini
    Member

    Because in the front page I have to display other elements too that are not from the category (an image slider), and then I have a different page showing the archive for the category.
    So I thought to have the following structure:
    * home.php: with a sidebar to include the slider as a widget, and a custom loop to show the last 6 posts from “Blog” category
    * A link in the menu pointing to the “Blog” category archive page.

  • Author
    Posts
Viewing 9 posts - 1 through 9 (of 9 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