Exclude categories by ID

时间:2014-03-19 作者:Phantasmix

我搜索了这个网站,尝试了各种方法从列表中排除类别1和类别7,但没有任何效果。没有错误,但也不会隐藏猫。

类别1和7不是空的,但我还想排除空类别,所以!空的必须留下。

<!-- category list with thumbs -->
<?php
$terms = apply_filters( \'taxonomy-images-get-terms\', \'\', array(\'taxonomy\' => \'category\') );

if ( ! empty( $terms ) ) {

  foreach( (array) $terms as $term ) {
      echo \'<div class="issue clear"><h3><a href="\' . esc_url( get_term_link( $term, $term->taxonomy ) ) . \'">\' . $term->name . \'</a></h3>\';
      echo \'<div class="grid col-120 hide"><a href="\' . esc_url( get_term_link( $term, $term->taxonomy ) ) . \'"><img src="IMG SRC" alt="" /></a></div>\';
      echo \'<div class="grid col-780 fit">\'. $term->description . \'</div></div>\';
  }

}
?>

1 个回复
SO网友:MBL

您可以尝试修改查询,以便在foreach, 工作方式与!empty(). 一个未经测试的示例:

<!-- category list with thumbs -->
<?php
$terms = apply_filters( \'taxonomy-images-get-terms\', \'\', array(\'taxonomy\' => \'category\') );
$exclude = array(1,7); //add the category IDs to exlcude here

if ( ! empty( $terms ) ) {

  foreach( (array) $terms as $term ) {

        //check the category\'s ID and output code
        //if it\'s not in the $exclude array
        if ( ! in_array($term->term_id, $exclude) ) {
            echo \'<div class="issue clear"><h3><a href="\' . esc_url( get_term_link( $term, $term->taxonomy ) ) . \'">\' . $term->name . \'</a></h3>\';
            echo \'<div class="grid col-120 hide"><a href="\' . esc_url( get_term_link( $term, $term->taxonomy ) ) . \'"><img src="IMG SRC" alt="" /></a></div>\';
            echo \'<div class="grid col-780 fit">\'. $term->description . \'</div></div>\';
        }//if in_array

    }//for each

}//if empty
?>

结束