Site logo

Archived topic

WP Show Posts on Homepage Hero Slider repeats content

5 replies · Started by Former User on March 2, 2020

Viewing posts 1–6 of 6

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

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

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?

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.

Thanks a lot Leo :)

No problem :)

This archived topic is closed to new replies.