kesernio
kesernio

Reputation: 115

Exclude category from list - Wordpress

I'm trying to exclude a category from displaying in the following list:

<?php
    $categories = get_categories( 'orderby=id&exclude=1,'. getOption('promo-categorie', false) );
    foreach( $categories as $category ) :
        $active = ( !is_home() && get_query_var( 'cat' ) == $category->term_id )? ' style="color: ' . getOption($category->category_nicename . '-color', false) . '"' : '';
        $catLink = ( get_query_var( 'cat' ) == $category->term_id ) ? get_bloginfo( 'wpurl' ) : get_category_link( $category->term_id );
?>
  <a class="nav-links" href="<?php echo ( get_query_var( 'sort' ) == 'list' )? add_query_arg( array( 'sort' => 'list' ), $catLink ) : $catLink ?>" <?php echo $active; ?>><?php echo $category->name; ?></a>
<?php
    endforeach;
?>

I'm a total newb with PHP, but from what I can tell "promo-categorie" is being excluded. In addition, I would like to exclude another category.

Any help would be appreciated.

Upvotes: 6

Views: 18703

Answers (1)

Bhumi Shah
Bhumi Shah

Reputation: 9474

You can exclude id in array.You can pass multiple ids in exclude parameter like

$args = array(  
    'hide_empty'               => 1,    
    'exclude'                  =>array(1,2,3) // desire id
); 

$categories = get_categories($args );

Upvotes: 14

Related Questions