dongpouda6700 2014-10-31 03:47 采纳率: 100%
浏览 39
已采纳

从列表中排除类别 - 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 2014-10-31 04:41
    关注

    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 );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题