How can I limiting the number of blog posts only on the homepage of Minimum?

Community Forums Forums Design Tips and Tricks How can I limiting the number of blog posts only on the homepage of Minimum?

This topic is: resolved

This topic contains 4 replies, has 3 voices, and was last updated by  giraffeweb 3 months, 3 weeks ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #43246

    Chris Moore
    Participant
    Post count: 136

    Hello,

    Looking for a way to limit the number of posts that show up only on the homepage of the Minimum child theme.

    I am currently editing this code found in the `home.php` file of the Minimum child theme:

    `add_action( ‘genesis_loop’, ‘minimum_grid_loop_helper’ );
    function minimum_grid_loop_helper() {

    if ( function_exists( ‘genesis_grid_loop’ ) ) {
    genesis_grid_loop( array(
    ‘features’ => 0,
    ‘feature_image_size’ => ‘featured’,
    ‘feature_image_class’ => ‘post-image’,
    ‘feature_content_limit’ => 0,
    ‘grid_image_size’ => 0,
    ‘grid_image_class’ => ‘alignnone’,
    ‘grid_content_limit’ => 250,
    ‘posts_per_page’ => 2, // added this
    ‘more’ => __( ‘[Read more]’, ‘minimum’ ),
    ) );
    } else {
    genesis_standard_loop();
    }

    }`

    It seems that the ‘posts_per_page’ in this code snippet is not doing it’s job of limiting the posts to only 2.

    Note: I have the SETTINGS –> READING “Blog pages show at most” set to 6 because I want other pages on the site to show 6 posts (like the archive and category pages). But I still want to limit the amount of posts that show on the homepage and I just can’t get it to work.

    Thanks for your help!


    Resepctfully, Chris Moore
    Web Dev, CSS Hacks, & Biz Consulting @ MooreCreativeIdeas.com / Blogging @ ReflectOnThis.com

    http://moorecreativeideas.com
    #43248

    Chris Moore
    Participant
    Post count: 136

    Well, looks like I solved it!

    I just added this to the `functions.php` and voila, only 2 posts on the homepage now!

    `/** Change the number of posts on homepage */
    add_action( ‘pre_get_posts’, ‘minimum_home_posts’ );
    function minimum_home_posts( $query ) {
    if( $query->is_main_query() && !is_admin() && is_home () ) {
    $query->set( ‘posts_per_page’, ‘2’ );
    }
    }`

    Comments are welcome!


    Resepctfully, Chris Moore
    Web Dev, CSS Hacks, & Biz Consulting @ MooreCreativeIdeas.com / Blogging @ ReflectOnThis.com

    #46529

    Dan B
    Participant
    Post count: 26

    Worked perfectly. Thanks!


    Dan @ ZindaMedia
    Freelance web development and design for non-profits and small businesses.

    #46679

    Chris Moore
    Participant
    Post count: 136

    Great to hear Dan! Glad it helped…


    Resepctfully, Chris Moore
    Web Dev, CSS Hacks, & Biz Consulting @ MooreCreativeIdeas.com / Blogging @ ReflectOnThis.com

    #117809

    giraffeweb
    Participant
    Post count: 10

    By the way – this worked on the Education theme too. I couldn’t get the http://www.studiopress.com/forums/topic/education-theme-homepage-blog-would-like-only-one-category-one-post-to-show/ one to work.

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

You must be logged in to reply to this topic.