下面的代码来自我的WP插件,该插件提供了一个过滤后的类别列表,不包括显示的“未分类”类别。然而,当用户从小部件设置选项中选择“显示层次结构”时,结果显示包括“未分类”。
考虑到我已将“exclude\\u tree”=>1放入$cat\\u args数组中。我错过了什么?
class My_Widget_Categories extends WP_Widget {
function My_Widget_Categories() {
$widget_ops = array( \'classname\' => \'widget_categories\', \'description\' => __( "filters out uncategorized categories" ) );
$this->WP_Widget(\'my_categories\', __(\'my Categories\'), $widget_ops);
}
function widget( $args, $instance ) {
extract( $args );
$title = apply_filters(\'widget_title\', empty( $instance[\'title\'] ) ? __( \'Categories\' ) : $instance[\'title\']);
$c = $instance[\'count\'] ? \'1\' : \'0\';
$h = $instance[\'hierarchical\'] ? \'1\' : \'0\';
$d = $instance[\'dropdown\'] ? \'1\' : \'0\';
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
$cat_args = array(\'orderby\' => \'name\', \'show_count\' => $c, \'hierarchical\' => $h, \'exclude_tree\' => 1);
if ( $d ) {
$cat_args[\'show_option_none\'] = __(\'Select Category\');
wp_dropdown_categories(apply_filters(\'widget_categories_dropdown_args\', $cat_args));