私はこのコードを持っている:私はシングルproducts.phpテンプレートに使用Wordpressのカスタムポスト - 現在の親の>ショー子供カテゴリ
<?php
$parent_cat_arg = array('hide_empty' => false, 'parent' => 0);
$parent_cat = get_terms('category',$parent_cat_arg);//category name
foreach ($parent_cat as $catVal) {
echo '<h2>'.$catVal->name.'</h2>'; //Parent Category
$child_arg = array('hide_empty' => false, 'parent' => $catVal->term_id);
$child_cat = get_terms('category', $child_arg);
echo '<ul>';
foreach($child_cat as $child_term) {
$term_link = get_term_link($child_term);
echo '<li><a href=" ' . esc_url($term_link) . ' ">' .$child_term->name . '</a></li>'; //Child Category
}
echo '</ul>';
}
?>
を。これは、すべてのカテゴリと私のカスタムポストタイプのすべてのサブカテゴリを出力する点を除いて、うまく動作します。
現在の親カテゴリのサブカテゴリのみを表示するにはどうすればよいですか?
私は、現在の単一の商品投稿に属するカテゴリとそのサブカテゴリだけを望むと思います。右? –
Correct Prateek –