- This topic has 7 replies, 2 voices, and was last updated 5 years, 5 months ago by Leo.
-
AuthorPosts
-
October 31, 2018 at 10:13 am #715763Eva
Hi there,
Would you please help me with the piece of code (PHP, CSS?) to filter the default Blog posts based on the Category type?
I’m not a programmer and what I’m trying to achieve is to display the blog posts here based on Category, without a need of using WP Show Posts. I would like to keep using the default blog functions on this page, with a bit more control over the design (buttons, pagination, sidebar widget design) and then use WP Show posts on another page to create a Portfolio/Event calendar by displaying a specific post category type – with a little different layout than blog post. This page can serve as a reference – Blog vs. Events
I believe it should be easily achievable using filters like this one, most likely $options[‘categories’] but I’m giving up on trying longer without coding knowledge 😉
I guess it should be a filter like “if the post category is/is not ‘Podujatie’ then display blog posts” but I also might be totally wrong
The last alternative is to use WP Show posts on both pages but I’d like to keep Blog within the default functionality
Thanks for your help in advance,
JanOctober 31, 2018 at 12:03 pm #715831LeoStaffCustomer SupportHi there,
This might help: https://generatepress.com/forums/topic/multiple-static-frontpage-selected-posts-on-frontpage/#post-157558
October 31, 2018 at 2:31 pm #715944EvaHi Leo,
I added the following snippet with Code-snippet but with no success
function exclude_category( $query ) { if ( $query->is_blog() && $query->is_main_query() ) { $query->set( 'Podujatie', 'podujatie' ); } } add_action( 'pre_get_posts', 'exclude_category' );
Any idea what else I could try? Maybe GP Elements may help?
Thank you
October 31, 2018 at 2:41 pm #715951LeoStaffCustomer SupportI’m confused. So are you trying to exclude category Podujatie from the blog page or only show category Podujatie on the blog page?
October 31, 2018 at 3:47 pm #715986EvaMy mistake. I wasn’t clear enough. I’m trying to exclude category Podujatie, slug ‘podujatie’ from the Blog page
October 31, 2018 at 4:38 pm #716001LeoStaffCustomer SupportThat case this should be the code:
https://generatepress.com/forums/topic/exclude-category-from-loop/#post-111543November 1, 2018 at 5:01 am #716315EvaI ended up with the following snippet. The filter
add_filter('pre_get_posts', 'excludeCat');
ruined the site speed for some reasonfunction exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '-7' ); } } add_action( 'pre_get_posts', 'exclude_category' );
Thanks for help
November 1, 2018 at 9:46 am #716588LeoStaffCustomer SupportNo problem 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.