Community Forums › Forums › Archived Forums › Design Tips and Tricks › Eleven40 theme: How to set a different loop for the homeopage?
Tagged: custom homepage, Eleven40, loop, pagination
- This topic has 12 replies, 3 voices, and was last updated 9 years, 9 months ago by
winnydejong.
-
AuthorPosts
-
August 14, 2013 at 8:40 am #56305
winnydejong
MemberHi,
I'd like to set a different loop for the homepage. I use the Eleven40 theme. I'd like the homepage to show the 5 latest blogposts: 1 featured and 4 posts in a grid. I figured the best way to do this would be by adding another loop - since I want all other (archive, categories, search) pages to show the latest 10 blogposts.
Since I'm a WordPress newbie I can use all help I can get. Hopefully you have an idea how exactly to do this... Thanks in advance!
Best regards, Winny
August 14, 2013 at 11:07 am #56344Holli
MemberI think you're saying you want to limit the number of posts to 5 on the home page. If that's correct, then go into the home.php file in your child theme and add the posts_per_page argument to the existing grid loop array like below:
function eleven40_grid_loop_helper() { if ( function_exists( 'genesis_grid_loop' ) ) { genesis_grid_loop( array( 'features' => 1, 'feature_image_size' => 0, 'feature_image_class' => 'alignleft post-image', 'feature_content_limit' => 0, 'grid_image_size' => 'grid-featured', 'grid_image_class' => 'grid-featured', 'grid_content_limit' => 250, 'posts_per_page' => 5, 'more' => __( '[Continue reading]', 'eleven40' ), ) ); } else { genesis_standard_loop(); } }
August 14, 2013 at 4:57 pm #56426winnydejong
MemberThanks for your suggestion Holli - unfortunately though, it doesn't seem to work... Any ideas?
August 14, 2013 at 9:08 pm #56448Holli
MemberLooks like it's changed for 2.0. Sorry about that. You can add this to the bottom of your functions.php file in your theme, and it should work. It will only the limit the posts to 5 on the home page.
//* Change the number of posts showing in the grid on the homepage add_action( 'pre_get_posts', 'eleven40_change_num_posts_in_grid' ); function eleven40_change_num_posts_in_grid( $query ) { global $wp_the_query; if( $query->is_main_query() && is_home() ) { $query->set( 'posts_per_page', '5' ); } }
August 15, 2013 at 1:39 am #56477winnydejong
MemberIt works great - thanks Holli! Is there any way to limit this to the frontpage?
August 15, 2013 at 2:29 pm #56649Holli
MemberThat should limit it to your home page if you haven't changed any settings in the theme. If you send me the link to your site, I can take a quick look at it.
August 15, 2013 at 2:44 pm #56655Brad Dalton
ParticipantGreat solution which doesn't get over ridden by the default WordPress Reading Settings so your archives aren't effected.
Also uses the is_home() conditional tag so only effects the home page
August 16, 2013 at 2:27 am #56740winnydejong
MemberActually when I start using the code Holli sent me, it also limited the number of posts on pages 2, 3, etc. instead of only on the frontpage. After some research I came up with this, and now only the frontpage shows 5, all other pages show 10 posts:
//* Limit the frontpage to only showing latest 5 posts - all other pages show 10 function frontpage_custom_post_count(&$query) { // show specific number of posts on frontpage $frontpagePostsCount = 5; if (is_front_page() and !is_paged()) { $query->query_vars['posts_per_page'] = $frontpagePostsCount; } // show configured posts on the rest of pages, offsetting the ones showed on frontpage if (is_front_page() and is_paged()) { $posts_per_page = isset($query->query_vars['posts_per_page']) ? $query->query_vars['posts_per_page'] : get_option('posts_per_page'); $query->query_vars['offset'] = (($query->query_vars['paged'] - 2) * $posts_per_page) + $frontpagePostsCount; } } add_action('pre_get_posts', 'frontpage_custom_post_count');
August 16, 2013 at 4:27 am #56773Brad Dalton
ParticipantYou could set that in the WordPress Reading Settings and then use this code which only uses 1 query:
This code displays 5 on the home page and the same number as your WordPress Reading Settings on paged archives.
August 16, 2013 at 3:05 pm #56900winnydejong
MemberThanks Brad for cleaning up the code 🙂 Works just great!
August 17, 2013 at 12:57 am #56999winnydejong
MemberHi!
Do you know how to change my pagination accordingly. At the homepage (with only 5 posts) you'll see page 1, 2, ... and 27 - while there is no page 27 since all other pages show 10 posts. When you're on the second page - which displays 10 posts - you'll see page 1, 2, ... and 14. Which is correct. This problem definitly has to do with changing the number of posts on the frontpage...
Any idea how to show the correct last pagenumber at the frontpage? Thanks in advance!!
August 17, 2013 at 3:28 am #57012Brad Dalton
ParticipantAugust 29, 2013 at 12:15 am #59439winnydejong
MemberMade another topic for the pagination thing - http://www.studiopress.community/topic/pagination-how-to-fix-and-add-to-eleven40-pro/, including the link to my site. Any idea how to fix the pagination on the frontpage?
And any idea how to include the same style pagination on another page?
Thanks, Winny
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.