我找到了解决办法。。。
“我的函数”页面现在看起来像:
<?php
class dropdown 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."\\"";
$output .= \'>\';
$output .= $pad.$cat_name;
if ( $args[\'show_count\'] )
$output .= \' (\'. $category->count .\')\';
if ( $args[\'show_last_update\'] ) {
$format = \'Y-m-d\';
$output .= \' \' . gmdate($format, $category->last_update_timestamp);
}
$output .= "</option>\\n";
}
}
?>
我的表单现在看起来像:
<form method="get" id="searchform" action="<?php echo home_url(); ?>">
<input type="text" onclick="this.value=\'\';" onfocus="this.select()" onblur="this.value=!this.value?\'Product Search...\':this.value;" value="Product Search..." name="s" id="s" class="left" />
<input type="image" src="<?php bloginfo(\'template_directory\') ?>/images/icosearch.png" id="searchsubmit" value=""/>
<?php
wp_dropdown_categories(
array(
\'child_of\' => 426,
\'class\' => \'styled\',
\'id\' => \'make\',
\'name\' => \'make\',
\'show_option_all\' => \'Make...\',
\'taxonomy\' => \'product_cat\',
\'walker\' => new dropdown
))
?>
<?php
wp_dropdown_categories(
array(
\'child_of\' => 427,
\'class\' => \'styled\',
\'id\' => \'model\',
\'name\' => \'model\',
\'show_option_all\' => \'Model...\',
\'taxonomy\' => \'product_cat\',
\'walker\' => new dropdown
))
?>
</form>
我的搜索页面现在看起来像:
<?php
$tmp[]=$_GET["model"];
$tmp[]=$_GET["make"];
$product_cat=array();
foreach($tmp as $v) {
if($v!="0")
$product_cat[]=$v;
}
if(count($product_cat)>0) {
$product_cat="&product_cat=".implode(",",$product_cat);
}
else {
$product_cat="";
}
$query=query_posts("s=$text".$product_cat);
$count =count($query);
if ($count == 0) {
echo \'No Results\';
}
elseif ($count == 1) {
echo \'\'.$count.\' Result\';
}
else {
echo \'\'.$count.\' Results\';
}
?>