[Resolved] Control posts shown on first page of blog

Home Forums Support [Resolved] Control posts shown on first page of blog

Home Forums Support Control posts shown on first page of blog

Viewing 6 posts - 31 through 36 (of 36 total)
  • Author
    Posts
  • #1448895
    Leo
    Staff
    Customer Support

    Hmm I actually tested the code and it worked for me.

    How are you adding it?

    Can you make sure it’s the correct syntax and quotation marks?

    function generate_home_category( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'category_name', 'secret-category' );
        }
    }
    add_action( 'pre_get_posts', 'generate_home_category' );
    #1448987
    Conor

    Leo, it worked this time!! Only one thing left to do is that I need to make it work with this other piece of code.

    add_action( ‘pre_get_posts’, function( $query ) {
    if ( is_admin() || ! $query->is_main_query() ) {
    return;
    }

    if ( is_category(‘your-category-slug’) ) {
    $query->set( ‘posts_per_page’, 15 );
    }

    if ( is_home() ) {
    $query->set( ‘posts_per_page’, 15 );
    }

    } );

    I think I may have messed up the syntax with this one too. My hope is that the home page will still only show secret category, and since I only have 6 posts in that category it should only show 6 posts.. then, I would like all the other category pages to show 15 per page.

    Thank you very much leo, you and the team are amazing.

    C

    #1449147
    Leo
    Staff
    Customer Support

    since I only have 6 posts in that category it should only show 6 posts.. then, I would like all the other category pages to show 15 per page.

    Hmm so wouldn’t it work if this is the only snippet:
    https://generatepress.com/forums/topic/control-posts-shown-on-first-page-of-blog/page/3/#post-1448895

    And the Blog pages show at most is set to 15?
    https://wordpress.org/support/article/settings-reading-screen/

    #1449153
    Leo
    Staff
    Customer Support

    I still think WP Show Posts is your best bet rather than trying to modify the loop that much.

    We were pretty close with the styling no?

    #1449211
    Conor

    Leo, I changed the settings in the reading tab, and now everything works perfectly.

    Thank you so much for all the help with this one.. You can check it out conorwriter.com – i have 6 articles on the home page, then I have the 15 on the latest articles category page

    This is exactly what I want and it works

    #1449218
    Leo
    Staff
    Customer Support

    Glad to hear 🙂

Viewing 6 posts - 31 through 36 (of 36 total)
  • The topic ‘Control posts shown on first page of blog’ is closed to new replies.