ただ親を出すだけの場合
<div class="jirei_other_cat">
<h4 class="h4_style title_class2 display_table">素材カテゴリ</h4>
<ul class="single_foot_menu">
<?php wp_list_categories(
array(
'title_li' => '',
'hide_empty' => 0,
'taxonomy' => 'built-cat',
'depth' => 1 , //-1
'orderby' => 'menu_order',//順番は指定します
//'exclude'=> array(2,5)
)
); ?>
</ul>
</div>
子も出す 記事がないカテゴリは非表示
<?php ///////////////////////// 子も出す //////////////////////////// ?>
<?php $trem = 'built-cat';
$hide_empty = 'true';
?>
<div class="jirei_other_cat">
<h4 class="h4_style title_class2 display_table">車メーカー</h4>
<ul class="single_foot_menu">
<?php wp_list_categories(
array(
'title_li' => '',
'hide_empty' => $hide_empty,
'taxonomy' => $trem,
'depth' => 1,
'orderby' => 'menu_order',//順番は指定します
//'exclude'=> array(2,5)
)
); ?>
</ul>
<?php
//wpリストカテゴリで子カテゴリがある場合、並び順を親の次に並ばせたいのでdeaps -1 では再現できなく、仕方なく、親のチルドレンを無理やり同じリストのように表示させると モバイル再現できず
//なので
//タクソノミーphpで タームに子があれば、親を取得して、リストを出す 一応なんとかこれで納得
$term_object = get_queried_object(); // タームオブジェクトを取得
// echo "<pre>";
// print_r($term_object);
// echo "</pre>";
$parent_id = $term_object->parent;
if($parent_id):
?>
<ul class="single_foot_menu">
<?php wp_list_categories(
array(
'title_li' => '',
'hide_empty' => $hide_empty,
'taxonomy' => $trem,
'depth' => 1,
'child_of' => $parent_id,
'orderby' => 'menu_order',//順番は指定します
//'exclude'=> array(2,5)
)
); ?>
</ul>
<?php endif;
//親ページで子のリストもだしたいなあ
//指定したIDの情報を返してくれる
$term_id = $term_object->term_id;
$taxonomy_name = $term_object->taxonomy;
$term_child = get_term_children( $term_id, $taxonomy_name);
// echo "<pre>";
// print_r($term_child);
// echo "</pre>";
if($term_child): //子があれば
?>
<ul class="single_foot_menu">
<?php wp_list_categories(
array(
'title_li' => '',
'hide_empty' => $hide_empty,
'taxonomy' => $trem,
'depth' => 1,
'child_of' => $term_id,
'orderby' => 'menu_order',//順番は指定します
//'exclude'=> array(2,5)
)
); ?>
</ul>
<?php endif; ?>
<br><br>
</div>