こんにちは、子カテゴリの選択リストを追加しようとしています。ここで 1 つの素敵なコードを見つけて正常に動作しますが、それを順序リストではなくドロップダウン選択として使用したいと考えています。誰でも私がそれをするのを手伝ってくれますか?
<?php
if (is_category()) {
$cat = get_query_var('cat');
$this_category = get_category($cat);
$this_category = wp_list_categories('hide_empty=0&hierarchical=true&orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID."&echo=0");
if($this_category !='<li>No categories</li>')
{
echo '<h3>Products</h3>';
echo '<ul>'.$this_category.'</ul>';
}
}
?>
foreachを使用しようとしましたが、うまくいきませんでした
<?php
if (is_category()) {
$cat = get_query_var('cat');
$this_category = get_category($cat);
$this_category = wp_list_categories('hide_empty=0&hierarchical=true&orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID."&echo=0");
if($this_category !='<li>No categories</li>')
{
echo '<h3>Products</h3>';
echo '<select>';
foreach($this_category as $list) {
echo '<option>'.$list.'</option>';
}
echo '</select>';
}
}
?>