好吧,没有这里的任何帮助。。。。。。。我能够找出如何更改选项并选择wp\\u dropdown\\u categories的值,以显示当前正在查看的分类法的子术语-首先,我将此代码放入我的函数文件中,该文件创建了一个walker类-
class SH_Walker_TaxonomyDropdown extends Walker_CategoryDropdown{
function start_el(&$output, $category, $depth, $args) {
$pad = str_repeat(\' \', $depth * 2);
$cat_name = apply_filters(\'list_cats\', $category->name, $category);
if( !isset($args[\'value\']) ){
$args[\'value\'] = ( $category->taxonomy != \'category\' ? \'slug\' : \'id\' );
}
$value = ($args[\'value\']==\'slug\' ? $category->slug : $category->term_id );
$output .= "\\t<option class=\\"level-$depth\\" data-filter-value=\\".".$value."\\"";
if ( $value === (string) $args[\'selected\'] ){
$output .= \' selected="selected"\';
}
$output .= \'>\';
$output .= $pad.$cat_name;
if ( $args[\'show_count\'] )
$output .= \' (\'. $category->count .\')\';
$output .= "</option>\\n";
}
}
这是我放在侧边栏中的代码-
<?php
//first get the current term
$current_term = get_term_by( \'slug\', get_query_var( \'term\' ), get_query_var( \'taxonomy\' ) );
//then set the args for wp_dropdown_categories
$args = array(
\'walker\'=> new SH_Walker_TaxonomyDropdown(),
\'value\'=>\'slug\',
\'child_of\' => $current_term->term_id,
\'taxonomy\' => $current_term->taxonomy,
\'hide_empty\' => 0,
\'hierarchical\' => true,
\'depth\' => 2,
\'title_li\' => \'\',
\'id\' => \'filter-select\',
\'class\' => \'filter option-set\',
\'show_option_all\' => All,
\'hide_if_empty\' => true
);
wp_dropdown_categories( $args );
?>