在制作wordpress列表模板的時候,經常會用到調用同錄分類目錄的情況,這段代碼完美解決了這一問題。

<?php
$cat = get_queried_object();
$list = wp_list_categories( [
    'taxonomy' => $cat->taxonomy,
    'child_of' => $cat->parent,
    'title_li' => '',
    'echo'     => 0,
] );
if ( $list ) {
    echo "<ul>$list</ul>";
}
?>