WordPress调用指定分类下的文章!WordPress主题系统模板的定义非常方便,但是在定制模板之前,我们有必要知道WordPress模板层次,了解WordPress是如何调用指定分类下的文章,这将有利于开发模板时合理利用资源及提高工作效率。
<ul>
<?php
$args=array(
'cat' => 1, // 分类ID
'posts_per_page' => 10, // 显示篇数
);
query_posts($args);
if(have_posts()) : while (have_posts()) : the_post();
?>
<li>
<a href="<?php the_permalink(); ?>" rel="external nofollow" ><?php the_title(); ?></a> //标题
<span>
<?php if (has_excerpt()) {
echo $description = get_the_excerpt(); //文章编辑中的摘要
}else {
echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 170,"……"); //文章编辑中若无摘要,自定截取文章内容字数做为摘要
} ?>
</span>
</li>
<?php endwhile; endif; wp_reset_query(); ?>
</ul>