2012-10-31 38 views
2

我有一个带有过滤器的产品页面。如果没有类别,我想隐藏“无类别”文本。在WordPress中隐藏“无类别”

<?php wp_list_categories(array('taxonomy' => 'products', 'orderby' => 'order', 'title_li' => '', 'child_of' => ($term->parent==0) ? $term->term_id : $term->parent)); ?> 

我该如何实现它?

回答

1

添加show_option_none到您的参数数组,并将其设置为空字符串:

<?php wp_list_categories(array('show_option_none' => '', 'taxonomy' => 'products', 'orderby' => 'order', 'title_li' => '', 'child_of' => ($term->parent==0) ? $term->term_id : $term->parent)); ?> 


您可能还需要重写代码一点,所以它更容易调试,而不是一个长线,如:

<?php 

$args = array(
    'taxonomy' => 'products', 
    'orderby' => 'order', 
    'title_li' => '', 
    'child_of' => ($term->parent == 0) ? $term->term_id : $term->parent 
    'show_option_none' => '', 
); 

wp_list_categories($args); 

?>