在wordpress模板制作,修改的时候常常需要调用不同分类里的文章。下面我给大家介绍一个方法:
按分类显示每个分类的最新文章,代码如下:(其中的1,3,4,5,6,7是你要显示的分类ID号)
<?php $display_categories = array(1,3,4,5,6,7); foreach ($display_categories as $category) { ?>
<div class="postlist">
<?php query_posts("showposts=5&cat=$category"); $wp_query->is_category = false; $wp_query->is_archive = false; $wp_query->is_home = true; ?>
<h3 class="posttitle"><span class="more"><a href="<?php echo get_category_link($category);?>">» 查看更多</a></span><?php single_cat_title(); ?></h3>
<ul>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php else : ?><p class="center">此分类暂无内容</p>
<?php endif; ?>
</ul>
</div>
<?php } ?>
显示指定分类的描述(1代表分类ID为1)
<?php echo category_description(1); ?>