dongpouda6700
dongpouda6700
采纳率100%
2014-10-31 03:47

从列表中排除类别 - 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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duanan1946 duanan1946 7年前

    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 );
    
    点赞 评论 复制链接分享

相关推荐