WordPress.org

Support

Support » How-To and Troubleshooting » Exclude more than one category?

Exclude more than one category?

  • I have been searching for a way to exclude more than one category of posts from displaying on the index page.
    I found a way to exclude one category (http://faq.wordpress.net/view.php?p=55) and how to exclude categories from being listed in the category list (http://faq.wordpress.net/view.php?p=56), but both aren’t what I’m looking for. I am converting from MT, and I am looking for a way to replicate what the MTCatEntries plugin offered.
    For example, for categories A, B, C, D and E, I only want posts from category A, C and E to be displayed on index page (and archives, too if that’s also possible).
    Any suggestions?
    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • TechGnome

    @techgnome

    Moderator

    Instead of excluding categories, try including jsut ones you do want:

    If (!isset($cat) ) {
    $cat = "1,3,6,7"; // Where 1,3,6,7 represent the IDs of the cats you DO want to show
    }

    This will work for the main page, not sure how it affects archives tho.
    TG

    TechGnome, where should I put this code? Oh, nevermind, I found it

    <?php
    /* Hack - show just a few categories */
    If (!isset($cat) ) {
    $cat = "1,3,6,7"; // Where 1,3,6,7 represent the IDs of the cats you DO want to show
    }
    /* --------------- */
    require('wp-blog-header.php');
    ?>

    Another question:
    I’ve been trying to use wiki’s exemple – http://www.wiki.wordpress.org/ShowOneCategory – but it’s not working on WP 1.2.
    Did anyone get success?

    By the way, thank you very very much, TechGnome. Your code saved my day. 🙂

    I want to exclude just one category from showing on the front page (I have a plugin that shows that category on the sidebar, so it shouldn’t appear on the main) I’ve tried hacking my-hacks.php and I’ve also tried http://faq.wordpress.net/view.php?p=55 but what they both seem to do is showing ALL the posts in the other categories. So I end up with a huge list of entries on my index page. Does anyone have a solution for this?

    Anyone?

    This was just what i was looking for fabioassis it worked like a charm! Thank you so much! 🙂

    And thats TechGnome for showing us the part that needed to be added.

    Thanks for this, I am going to try this one out now. I am glad I didn’t have to start a new thread.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Exclude more than one category?’ is closed to new replies.
Skip to toolbar