- This topic has 9 replies, 2 voices, and was last updated 3 years, 4 months ago by
David.
-
AuthorPosts
-
September 25, 2019 at 8:38 pm #1019222
Kelvin
Dear Sir/Madam,
This is the first I use the Site Library “SlideOut” I have different post categories, I want to limit the blog archive page to show some of the categories, how can I do that? By the way, for the single post, I also want to have the navigate with same category post only. How can I do that?
Best regards,
Kelvin
September 26, 2019 at 4:03 am #1019432David
StaffCustomer SupportHi there,
1. You would need to use this PHP snippet:
function exclude_categories_home( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '-1, -5, -10' ); } return $query; } add_filter( 'pre_get_posts', 'exclude_categories_home' );
The -1, -5, -10 are the Category ID’s you want to remove. They must be prefixed by the
-
2. Post Navigation set to within same category – try this snippet:
add_action( 'after_setup_theme', 'tu_category_specific_post_navigation' ); function tu_category_specific_post_navigation() { add_filter( 'generate_category_post_navigation', '__return_true' ); }
https://docs.generatepress.com/article/adding-php/
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/September 26, 2019 at 6:29 am #1019554Kelvin
Dear David,
Sorry, both don’t work on my site. I try put the $query->set() outside $query->is_home if block, all categories post show up.
When I view a single post, another category post still shows up.
Best regards,
Kelvin.
September 26, 2019 at 8:03 am #1019755David
StaffCustomer SupportHow did you add the code?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/September 26, 2019 at 8:22 am #1019766Kelvin
Dear David,
Sorry, I placed to the wrong php script.
How can I include the category instead of excluding it?
Best regards,
Kelvin
September 26, 2019 at 8:40 am #1019793David
StaffCustomer SupportJust remove the
-
ie.-5
means remove cat ID 5. Whereas5
means include cat ID 5.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/September 26, 2019 at 8:44 am #1019795Kelvin
Dear David,
If I change the $query->set( ‘cat’, ‘3, 4’ );
I got some problem, please visit https://prnt.sc/pbcs2j
September 26, 2019 at 9:48 am #1019845David
StaffCustomer SupportI made an edit to the original code above. Use that and change it to the categories you want to select as per the last reply.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/September 28, 2019 at 5:09 am #1021158Kelvin
Dear David,
Problem is solved.
Best regards,
Kelvin
September 28, 2019 at 5:13 am #1021159David
StaffCustomer SupportYou’re welcome
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.