我们在做wordpress网站的时候常常需要调用子分类的数据和列表,

通过下面代码就可以实现:

<?php
    global $cat;
    $cats = get_categories(array(
        'child_of' => 18,
        'parent' => $cat,
        'hide_empty' => 0
    ));
	
    $c = get_category($cat);
    if(empty($cats)){
?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <?php endwhile; ?>
    <?php else: ?>
    <?php endif; ?>

<?php ?>

<?php
}else{
				$i=1;
	  foreach($cats as $the_cat){
        $posts = get_posts(array(
            'category' => $the_cat->cat_ID,
            'numberposts' => 10,
        ));
		if (function_exists('z_taxonomy_image_url'))
echo z_taxonomy_image_url();
        if(!empty($posts)){
			
            echo '
            <section class="step-sections">
<div class="mml-container">
<div class="step-img-wrap">
<img src="'.z_taxonomy_image_url(%20$the_cat->term_id%20).'">
</div>
<div class="step-detail-wrap">
<h2 class="step-title"><span>'.$i.'</span>'.$the_cat->name.'</h2>
<p>'.$the_cat->description.'</p>
<ul class="slider-control">';
                    foreach($posts as $post){
$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
                        echo '<li><i class="icon-right-dir"></i>'.$post->post_title.'</li>';
                    }
                echo '
                        </ul>
</div>              
</div>
</section>';
$i++;			
        }
	

    }
		
}
	?>		

里面用到的子分类缩略图的调用需要用到插件:Categories Images 

分类id和调用文章数量 直接修改数字就可以了。