我在Wordpress论坛上问过这个问题,但现在没有得到任何回复,我希望我可以在这里问。
我找到密码了here 我的代码是:
function exc_custom_taxonomy_dropdown( $taxonomy, $orderby, $order, $hierarchical, $show_count, $name) {
$args = array(
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'hierarchical\' => true,
\'show_count\' => true,
);
$terms = get_terms( $taxonomy, $args );
$name = ( $name ) ? $name : $taxonomy;
if ( $terms ) {
printf( \'<select name="%s" class="postform">\', $name );
foreach ( $terms as $term ) {
printf( \'<option value="%s">%s (%s)</option>\', $term->slug, $term->name, $term->count );
}
print( \'</select>\' );
}
}
?>
<form role="search" method="get" id="equipfilter" action="<?php bloginfo(\'url\'); ?>">
<fieldset>
<?php exc_custom_taxonomy_dropdown( \'exc_equipment_cat\', \'name\', \'ASC\', true, true, \'exc_equipment_cat\'); ?>
- </fieldset>
<fieldset>
<legend>Kw Range:</legend>
<input type="text" name="kw_min" placeholder="from" value><br />
<input type="text" name="kw_max" placeholder="to" value>
</fieldset>
<fieldset>
<legend>Price Range:</legend>
<input type="text" name="pr_min" placeholder="from" value><br />
<input type="text" name="pr_max" placeholder="to" value>
</fieldset>
<input type="submit" id="filtersubmit" value="Search" />
</form>
它为我的自定义分类法创建了一个下拉列表。它100%工作,我只是不能让它显示我的类别与层次结构,就像它与wp\\U下拉式菜单\\U类别。
我曾尝试将wp\\u dropdown\\u categories用于walker,但它会输出一个slug网站。com?equipment\\u cat代替网站。com/equipment\\u目录。
这是我的代码,用于walker的wp\\u下拉列表\\u类别。
<?php
// Equipment Category Dropdown, thanks https://gist.github.com/2902509
class Walker_SlugValueCategoryDropdown extends Walker_CategoryDropdown {
function start_el(&$output, $category, $depth, $args) {
$pad = str_repeat(\' \', $depth * 3);
$cat_name = apply_filters(\'list_cats\', $category->name, $category);
$output .= "\\t<option class=\\"level-$depth\\" value=\\"".$category->slug."\\"";
if ( $category->term_id == $args[\'selected\'] )
$output .= \' selected="selected"\';
$output .= \'>\';
$output .= $pad.$cat_name;
if ( $args[\'show_count\'] )
$output .= \' (\'. $category->count .\')\';
if (isset ( $args[\'show_last_update\'] ) ) {
$format = \'Y-m-d\';
$output .= \' \' . gmdate($format, $category->last_update_timestamp);
}
$output .= "</option>\\n";
}
}
?>
<form role="search" method="get" id="equipfilter" action="<?php bloginfo(\'url\'); ?>">
<fieldset>
<?php
$dropdown_args = array(
\'taxonomy\' => \'exc_equipment_cat\',
\'name\' => \'equipment_cat\',
\'show_option_none\' => \'Select category\',
\'show_count\' => 1,
\'orderby\' => \'name\',
\'hierarchical\' => true,
\'echo\' => 1,
\'walker\' => new Walker_SlugValueCategoryDropdown);
wp_dropdown_categories( $dropdown_args );
?>
</fieldset>
<fieldset>
<legend>Kw Range:</legend>
<input type="text" name="kw_min" placeholder="from" value><br />
<input type="text" name="kw_max" placeholder="to" value>
</fieldset>
<fieldset>
<legend>Price Range:</legend>
<input type="text" name="pr_min" placeholder="from" value><br />
<input type="text" name="pr_max" placeholder="to" value>
</fieldset>
<input type="submit" id="filtersubmit" value="Search" />
</form>
非常感谢您的帮助。