Tagged: x
-
AuthorPosts
-
May 1, 2016 at 4:28 am #907639
markusp80ParticipantHi!
I am wondering if there is a way to exclude certain blog categories from all places, for example:
– the latest blog posts on the start page
– the blog start page/blog feed
– the side widgetI’ve found some simple plugins but they only exclude the chosen category from the blog start page/blog feed.
Help appreciated!
/Markus
May 1, 2016 at 9:00 am #907853
ThaiModeratorHi Markus,
Please add the following code under functions.php file locates in your child theme:
function exclude_category( $query ) { if ( !is_admin() ) { $query->set( 'cat', '-123,-456' ); } } add_action( 'pre_get_posts', 'exclude_category' );Replace 123, 456 with your category ID.
Let us know how it goes!
May 1, 2016 at 10:13 am #907907
markusp80ParticipantNot too well!
Got this error message:
Parse error: syntax error, unexpected ‘&’ in /customers/1/f/a/markusp.se/httpd.www/wp-content/themes/x-child/functions.php on line 56I want to remove category ID 342. But I pasted the text exactly as your wrote it and just changed the numbers to 342 and 337 to try it out. Like this:
function exclude_category( $query ) { if ( !is_admin() ) { $query->set( 'cat', '-342,-337' ); } } add_action( 'pre_get_posts', 'exclude_category' );/Markus
May 1, 2016 at 10:17 am #907910
markusp80ParticipantMy bad!
It got a bit weird when I copied the text from my e-mail, then it looked like in the attached image with all the & #039 and stuff. But now it works exactly as I want to, thank you very much!
May 1, 2016 at 11:54 am #908053
ThaiModeratorGlad it worked 🙂
Next time, you should copy the code from the forum.
May 1, 2016 at 12:03 pm #908060
markusp80ParticipantWill do! 🙂
May 1, 2016 at 9:07 pm #908425
LelyModeratorCheers!
Feel free to open a new thread again if you still have questions.Always,
X -
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-907639 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
