Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #907639
    markusp80
    Participant

    Hi!

    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 widget

    I’ve found some simple plugins but they only exclude the chosen category from the blog start page/blog feed.

    Help appreciated!

    /Markus

    #907853
    Thai
    Moderator

    Hi 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!

    #907907
    markusp80
    Participant

    Not 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 56

    I 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

    #907910
    markusp80
    Participant

    My 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!

    #908053
    Thai
    Moderator

    Glad it worked 🙂

    Next time, you should copy the code from the forum.

    #908060
    markusp80
    Participant

    Will do! 🙂

    #908425
    Lely
    Moderator

    Cheers!
    Feel free to open a new thread again if you still have questions.

    Always,
    X

  • <script> jQuery(function($){ $("#no-reply-907639 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>