• Resolved Divvy

    (@divvy)


    Hello,

    Can someone please give me a little help here?
    I need to exclude a category (ID76) from listing, but I’m too newbie to do this. I already searched for a solution but couldnt do it myself.

    Here’s my code:

    <?php $categories = get_the_category();
     if($categories){
    ?>
     <div id="includes">CATEGORIES</div>
     <?php
    foreach ( $categories as $category ) { 
    echo '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ><div class="tags">'.$category->name.'</div></a>'; 
    }
    ?>

    Thank you guys! ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    foreach ( $categories as $category ) { 
      if ( $category->term_id == 76 ( { 
       continue;
      }
      echo '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ><div class="tags">'.$category->name.'</div></a>'; 
    }

    or

    foreach ( $categories as $category ) { 
      if ( $category->term_id != 76 ( { 
        echo '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ><div class="tags">'.$category->name.'</div></a>'; 
        }
    }
    Thread Starter Divvy

    (@divvy)

    Hey Steve,

    Thank you very much for your fast reply ??
    I tried what you said:

    <?php $categories = get_the_category();
     if($categories){
    ?>
     <div id="includes">CATEGORIES</div>
     <?php
    foreach ( $categories as $category ) { 
      if ( $category->term_id == 76 ( { 
       continue;
      }
      echo '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ><div class="tags">'.$category->name.'</div></a>'; 
    }
    ?>

    But I got this error:

    Parse error: syntax error, unexpected ‘(‘ in /home/usernamehere/public_html/wp-content/themes/templatenamehere/single.php on line 182

    Any ideas? ??

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Look at my code — do you see the typo after ==76 ?

    Thread Starter Divvy

    (@divvy)

    Ohhh, I see…

    if ( $category->term_id == 76 ( {

    Should be:

    if ( $category->term_id == 76 ) {

    Is working perfectly! Thank you very much ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to exclude category from get_the_category?’ is closed to new replies.