我正在尝试在我的选择选项中显示另一个级别的子类别。
我设法弄到了一个。。。我怎样才能得到另一个?
<?php
$taxonomies = array(CUSTOM_CAT_TYPE);
$args = array(\'orderby\' => \'count\', \'hide_empty\' => 0);
$myterms = get_terms($taxonomies, $args);
$output = "<select class=\\"select\\" name=\'select_cat\' title=\\"Select Category\\">";
$output .= "<option value=\'\'>Selecteer Rubriek</option>";
foreach ($myterms as $cate)
{
if($cate->parent == 0)
{
$catename = "";
$catename = $cate->name;
$output .=\'<option disabled="disabled" value="\'.$cate->term_id.\'">\'.$catename. \'</option>\';
foreach ($myterms as $subcate)
{
if($subcate->parent == $cate->term_id)
{
$catename = "";
$catename = $subcate->name;
$output .=\'<option value="\'.$subcate->term_id.\'">\'.\' \'.$catename.\'</option>\';
foreach ($subcate as $subsubcate)
{
if($subsubcate->parent == $cate->term_id)
{
$catename = "";
$catename = $subsubcate->name;
$output .=\'<option value="\'.$subsubcate->term_id.\'">\'.\' \'.$catename.\'</option>\';
}
}
}
}
}
}
$output .="</select>";
echo $output;
?>
有什么想法吗?!或者也许是一种更好的方式来达到我想要的目的!:)
SO网友:2611
找到了解决方案!:)
$taxonomies = array(CUSTOM_CAT_TYPE);
foreach($taxonomies as $tax)
{
$args = array(
\'orderby\' => \'name\',
\'show_count\' => 1,
\'pad_counts\' => 1,
\'hierarchical\' => 1,
\'hide_empty\' => 0,
\'taxonomy\' => $tax,
);
wp_dropdown_categories( $args );
}
谢谢你的帮助!