Community Forums › Forums › Archived Forums › General Discussion › Genesis loop for one category in home
Tagged: loop
- This topic has 8 replies, 2 voices, and was last updated 10 years, 1 month ago by marcello.vicidomini.
-
AuthorPosts
-
March 16, 2014 at 12:30 pm #95173marcello.vicidominiMember
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 #95205Brad DaltonParticipantMarch 17, 2014 at 2:43 am #95256marcello.vicidominiMemberHello 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 #95260Brad DaltonParticipantYes, you can see the examples on the Codex which you can include in the code.
March 19, 2014 at 6:05 am #95644marcello.vicidominiMemberHello 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 #95651Brad DaltonParticipantNever use query_posts http://en.wp.obenland.it/never-use-query-posts-again/
March 19, 2014 at 6:53 am #95653marcello.vicidominiMemberOk, that was clear 😀
Should I use WP_Query instead?
March 19, 2014 at 7:00 am #95655Brad DaltonParticipantWhy don't you simply display your category archive page on the front page?
March 19, 2014 at 7:06 am #95656marcello.vicidominiMemberBecause 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. -
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.