[Wordpress Help] exclude a category from get_the_category

Discussion in 'PHP' started by Divvy, Jul 15, 2008.

  1. #1
    Hi friends,

    Can someone please help me?
    Basically, I'm using a specific/secret category to show all my posts EXCEPT one category, and I'm using this category on my index page. (Think CMS: almost all my posts are in the "artwork" category, as well as several others. Then I have a "press" category for the other posts..) I don't want "artwork" listed when I call get_the_category from within a post; I just want its other cats listed.

    I found the solution for that with this code:

    <?php foreach((get_the_category()) as $cat) {
    if (!($cat->cat_name=='artwork')) echo $cat->cat_name . ' ';
    } ?>
    Code (markup):
    But now I have another problem...
    Is it possible to exclude multiple categories instead of just one?
    I´ve tried this code, but didnt help me:

    <?php
      foreach((get_the_category()) as $cat) {
        if (
          $cat->cat_name!=='one' ||
          $cat->cat_name!=='two' ||
          $cat->cat_name!=='three' ||
          $cat->cat_name!=='four'
        ) echo $cat->cat_name . ' ';
      }
    ?>
    Code (markup):
    Can someone help me in here, please? I really appreciate...
    Many thanks!

    P.S. If you can do it this with the_category function, will be better, because I need that categories with href (link) :)
     
    Divvy, Jul 15, 2008 IP
  2. thundercow

    thundercow Well-Known Member

    Messages:
    246
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Well, you could use "list_cats", but I am not sure if that will work for you...I think listcats gives you the link as well...

    <?php wp_list_cats('exclude="1,2"'); ?>

    change 1 and 2 to the categories you want excluded. You can exclude more of them by adding their IDs separated by commas.
     
    thundercow, Jul 18, 2008 IP