阿里云服务器

我们在做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( $the_cat->term_id ).'">
</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和调用文章数量 直接修改数字就可以了。

相关阅读:
  • wordpress搜索功能优化:只搜索指定分类的文章
  • WordPress无用数据清理插件:WPDBSpringClear
  • 设置WordPress一级分类不显示二级分类文章的方法
  • wordpress下拉菜单设置方法
  • WordPress页面添加自定义摘要功能
  • wordpress文章页调用当前分类名和链接的方法
  • wordpress特色图片地址调用方法
  • wordpress 调用分类列表 不同的列表样式
  • WordPress分别循环输出多个分类的最新文章