Eleven40 theme: How to set a different loop for the homeopage?

Community Forums Forums Design Tips and Tricks Eleven40 theme: How to set a different loop for the homeopage?

This topic is: resolved

This topic contains 12 replies, has 3 voices, and was last updated by  winnydejong 1 year, 1 month ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #56305

    winnydejong
    Participant
    Post count: 27

    Hi,

    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

    #56344

    Holli
    Participant
    Post count: 6

    I 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();
    	}
    
    }
    #56426

    winnydejong
    Participant
    Post count: 27

    Thanks for your suggestion Holli – unfortunately though, it doesn’t seem to work… Any ideas?

    #56448

    Holli
    Participant
    Post count: 6

    Looks 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' );
    		}
    }
    #56477

    winnydejong
    Participant
    Post count: 27

    It works great – thanks Holli! Is there any way to limit this to the frontpage?

    #56649

    Holli
    Participant
    Post count: 6

    That 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.

    #56655

    braddalton
    Participant
    Post count: 10254

    Great 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


    #56740

    winnydejong
    Participant
    Post count: 27

    Actually 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:

    [php]//* 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’);[/php]

    • This reply was modified 1 year, 2 months ago by  winnydejong. Reason: code didn't looked right
    • This reply was modified 1 year, 2 months ago by  winnydejong. Reason: code didn't looked right
    #56773

    braddalton
    Participant
    Post count: 10254

    You 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.


    #56900

    winnydejong
    Participant
    Post count: 27

    Thanks Brad for cleaning up the code :) Works just great!

    #56999

    winnydejong
    Participant
    Post count: 27

    Hi!

    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!!

    #57012

    braddalton
    Participant
    Post count: 10254
    #59439

    winnydejong
    Participant
    Post count: 27

    Made another topic for the pagination thing – http://www.studiopress.com/forums/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

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.