[Resolved] "Make first post featured" leads to uneven number of remaining posts

Home Forums Support [Resolved] "Make first post featured" leads to uneven number of remaining posts

Home Forums Support "Make first post featured" leads to uneven number of remaining posts

  • This topic has 12 replies, 3 voices, and was last updated 4 years ago by Tom.
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #724036
    Florian

    Hello,
    when I make my first post big with “Make first post featured”, the remaining posts are shown in an uneven number. Wouldn’t it make more sense to fill up all the remaining space?
    Take a look at my front page to see an example.

    #724118
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Right now, the featured post counts towards the posts per page option set in “Settings > Reading”.

    To make things even when using a featured image, you’ll want to increase that posts per page option by 1 πŸ™‚

    #724239
    Florian

    Thank you!

    #724240
    Florian

    Unfortunately this breaks the 2nd page where there is no featured post.

    #724602
    Tom
    Lead Developer
    Lead Developer

    Give this a shot:

    add_action( 'pre_get_posts', function( $query ) {
        if ( ! function_exists( 'generate_blog_get_defaults' ) ) {
            return;
        }
    
        $settings = wp_parse_args(
            get_option( 'generate_blog_settings', array() ),
            generate_blog_get_defaults()
        );
    
        if ( ! is_admin() && $query->is_main_query() && $settings['featured_column'] && ! is_paged() ) {
            $query->set( 'posts_per_page', get_option( 'posts_per_page' ) + 1 );
        }
    } );

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    #724617
    Florian

    Thank you, it works! I left a little tip earlier today on your donate page. I’m gonna do that from time to time for your great help!

    #724776
    Tom
    Lead Developer
    Lead Developer

    Thanks so much! Really appreciate it πŸ™‚

    #1144980
    Nacho

    Dear Tom,

    The code worked great for me!

    To reach excellence I would like to ask you a second question about it:

    The first post on the 2nd page of the blog is also shown as the last post on the first page.

    Is there any way to make this post not repeat?

    Thank you very much for the support!

    #1145119
    Tom
    Lead Developer
    Lead Developer

    Hmm, that doesn’t sound right. I suppose you could try removing this part of the code: && ! is_paged()

    #1146055
    Nacho

    Now it works perfect, thank you!!

    #1146248
    Tom
    Lead Developer
    Lead Developer

    You’re welcome πŸ™‚

    #1230917
    Nacho

    Dear developers, the code has stopped working.

    Has there been any change in the last update that affected this?

    Thanks for the support!

    #1231544
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    No, that code should still work as always.

    Has anything else changed on your site? Maybe try deactivating your plugins one by one to check for conflicts.

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.