通常博主会在在博客侧栏sidebar或其它位置按时间顺序显示发表的最新文章列表,但部分wordpress博主希望只显示某个分类的最新文章列表,而不是显示全站最新文章列表,以下代码可以实现显示wordpress某分类最新文章列表。
在想要调用分类最新文章列表的地方添加以下代码:
<?php
query_posts('showposts=1&cat=3');
while(have_posts()) : the_post();
?>
<ul>
<li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
<ul><li><?php the_content(); ?></li>
</ul>
</li>
</ul>
<?php endwhile; ?>
其中showposts后面的数码表示显示的文章数量;cat后面的数值表示分类ID。