[Resolved] WP Show Posts on Homepage Hero Slider repeats content

Home Forums Support WP Show Posts on Homepage Hero Slider repeats content

  • This topic has 5 replies, 2 voices, and was last updated 3 months ago by Leo.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1182734
    Sara

    Hello,

    How can I do so on homepage post listing not to repeat same posts showing on hero slider on WP Show Posts, Is it possible that on hero it shows last 4 published posts and for listing to start from fifth position for example so it does not repeat content?

    Thanks,

    Sara

    #1182846
    Leo
    Staff
    Customer Support

    Hi there,

    Give this PHP snippet a shot:

    add_filter( 'pre_get_posts', function( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $offset = 4;
            $ppp = get_option('posts_per_page');
    
            if ( $query->is_paged ) {
                $page_offset = $offset + ( ($query->query_vars['paged']-1) * $ppp );
                $query->set('offset', $page_offset );
            } else {
                $query->set('offset',$offset);
            }
        } else {
            return $query;
        }
    } );

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

    Let me know if this helps 🙂

    #1183906
    Sara

    Hello Leo,

    PHP snippet work perfectly, thanks a lot 🙂

    Just one last question all demo content from this plugin “Code Snippets” should I remove it all? For security reasons?

    #1183936
    Leo
    Staff
    Customer Support

    The demo content shouldn’t come from a plugin code Code Snippets – we actually can’t import that plugin with sites.

    You should be able to safely remove that if you don’t have any custom functions added within the plugin.

    #1187757
    Sara

    Thanks a lot Leo 🙂

    #1187989
    Leo
    Staff
    Customer Support
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.