Wordpress:query_posts - 如何显示多个帖子

时间:2011-03-21 19:57:12

标签: wordpress

我正在构建一个自定义WP主题(基于Chris Coyier在lynda.com上的教程),该主题显示了主页上最新博客文章的片段(博客本身不是该网站的主页)。我目前只显示一个帖子,但希望能够显示两个或更多帖子。这是当前的代码:

   <?php query_posts("posts_per_page=1"); the_post(); ?>
   <div class="date_home">Posted <?php the_time('F jS, Y') ?></div>
   <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
   <?php the_content('Continue Reading &#8594;'); ?>

我原以为会改变

posts_per_page=1

posts_per_page=2

可以做到这一点,但它不起作用。

任何帮助表示赞赏。谢谢!

1 个答案:

答案 0 :(得分:1)

需要更换:
<?php query_posts("posts_per_page=1"); the_post(); ?>

<?php query_posts('posts_per_page=5'); if (have_posts()) : while (have_posts()) : the_post();?>

完整代码如下:

<?php query_posts('posts_per_page=5');  
if (have_posts()) : while (have_posts()) : the_post();?>
<div class="date_home">Posted <?php the_time('F jS, Y') ?></div>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_content('Continue Reading &#8594;'); ?>
<?php endwhile; endif; wp_reset_query();?>