- This topic has 8 replies, 3 voices, and was last updated 3 years, 2 months ago by Leo.
-
AuthorPosts
-
February 3, 2021 at 10:02 am #1644519JORGE
Hello, I would like to know if there is any way to filter the entries that are shown in the home.
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!
February 3, 2021 at 11:01 am #1644602YingStaffCustomer SupportHi JORGE,
Did you forget to link the site? 🙂
February 3, 2021 at 11:06 am #1644613JORGESorry, https://cutt.ly/1kgNSUg
February 3, 2021 at 11:14 am #1644630YingStaffCustomer SupportYou 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-1603826Let me know how it works.
February 3, 2021 at 12:19 pm #1644720JORGEHi, 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.
February 3, 2021 at 12:24 pm #1644726LeoStaffCustomer SupportTry 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/
February 4, 2021 at 4:18 am #1645358JORGEIt works perfect, thanks a lot!
February 4, 2021 at 1:40 pm #1646120JORGEHi, 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.
February 4, 2021 at 4:00 pm #1646234LeoStaffCustomer SupportHi 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.
-
AuthorPosts
- You must be logged in to reply to this topic.