我在网上找到了此代码,但在父类别上显示所有子类别:
<?php
$this_category = get_category( $cat );
$child_categories = get_categories( array( \'child_of\' => $this_category->cat_ID,\'depth\' => 1));
foreach( $child_categories as $category ) {
$category_url = get_category_link( $category->term_id );
$category_name = $category->cat_name; ?>
<div class="col3">
<img src="<?php echo z_taxonomy_image_url($category->term_id, array(365, 165)); ?>">
<h3><a href="<?php echo $category_url?>"><?php echo $category_name?></a></h3>
</div><?php
}
例如,如果我有
Parent
-Child
--Child 2
---Child 3
Parent 2
当有人单击Child时,应该只显示Child 2。现在,当有人单击子项时,此代码同时显示子项2和子项3。