1.先在function.php里面添加下面的代码:
function get_category_root_id($cat) { $this_category = get_category($cat); // 取得当前分类 while($this_category->category_parent) // 若当前分类有上级分类时,循环 { $this_category = get_category($this_category->category_parent); // 将当前分类设为上级分类(往上爬) } return $this_category->term_id; // 返回根分类的id号 } 2.在分类页面添加下面代码,可以灵活循环调用当前分类下的二级分类以及分类图
<?php
$args=array(
‘child_of’=> get_category_root_id($cat),
‘hide_empty’=>’0’,
);
$categories=get_categories($args);
foreach($categories as $category) {?>
<a href=”<?php%20echo%20get_category_link(%20$category->term_id%20)%20;?>” title=”<?php echo $category->name;?>”>
<img src=”<?php%20echo%20z_taxonomy_image_url($category->term_id);%20?>” alt=”<?php echo get_cat_name($categoryzi->term_id); ?>” class=”home-img”>
<div class=”navcaption”><?php echo $category->name;?></div>
</a >
<?php } ?>