[Support request] Filter for home items

Home Forums Support [Support request] Filter for home items

Home Forums Support Filter for home items

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1644519
    JORGE

    Hello, I would like to know if there is any way to filter the entries that are shown in the home.

    My site is

    You can see in the Home that there are 4 featured items in carousel form, but then then they are displayed again in the list.

    Items featured in the header are a GP element, using the plugin wp_show_posts

    Is there a way to have a filter that prevents showing the last 4 articles published in the post list home? This is how the 4 most recent ones remain on the carousel and the others on the list.

    Thanks a lot!

    #1644602
    Ying
    Staff
    Customer Support

    Hi JORGE,

    Did you forget to link the site? 🙂

    #1644613
    JORGE
    #1644630
    Ying
    Staff
    Customer Support

    You could add a specific category for these 4 posts, eg. featured-posts.

    Then you can use this solution:
    https://generatepress.com/forums/topic/how-to-hide-some-posts-from-blog-page/#post-1603826

    Let me know how it works.

    #1644720
    JORGE

    Hi, the problem is that those 4 publications that are seen in a carousel are the 4 most recent, as they are published they move automatically.

    #1644726
    Leo
    Staff
    Customer Support

    Try this PHP snippet:

    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/

    #1645358
    JORGE

    It works perfect, thanks a lot!

    #1646120
    JORGE

    Hi, the filter has a problem and that is that there are times when it does not show some articles.

    In the carousel only articles of 2 categories are shown, the others never go through the carousel, they are printed directly in the list. The problem is that with the code snippet those articles that we do not print in the carousel are not printed in the list either, they remain hidden until more are published.

    #1646234
    Leo
    Staff
    Customer Support

    Hi Jorge,

    Unfortunately your request would require modifying the WordPress post loop pretty extensively which is outside of the forum support scope.

    You could try checking with WordPress’ support team and see if they are able to help or open a topic in general WordPress forum like this:
    https://wordpress.stackexchange.com/

    The post loop is completely handled by WordPress itself so if the code works in a Twenty series WP theme, the exact code would work in GeneratePress as well.

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