使用循环的嵌套来实现WordPress调用指定ID父分类下的子分类,二、三级分类都可以实现。代码如下:

<?php
$args=array(
'child_of'=> '666',
'hide_empty'=>'0',
);
$categories=get_categories($args);
foreach($categories as $category) {?>
 
<h5 class="title"><a href="<?php echo get_category_link( $category->term_id ) ;?>" title="' . $category->name.'"><?php echo $category->name;?></a></h5>
<ul>
<?php
$argszifenlei=array(
'child_of'=> $category->term_id,
'hide_empty'=>'0',
);
$categorieszifenlei=get_categories($argszifenlei);
foreach($categorieszifenlei as $categoryzifenlei) {
echo '<li ><a href="' . get_category_link( $categoryzifenlei->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $categoryzifenlei->name ) . '" ' . '>' . $categoryzifenlei->name.'</a></li>';
}
?>
</ul>';
<?php }
?>