2011-03-21 64 views
0

我正在建立一個自定義WP主題(基於克里斯Coyier的教程在lynda.com),顯示主頁上最新的博客文章剪輯(博客本身是而不是網站的主頁)。我目前只顯示一個帖子,但想要顯示兩個或更多帖子的選項。下面是當前的代碼:WordPress的:query_posts - 如何顯示多個職位

<?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

需要更換:
<?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();?> 
+1

您的原始代碼沒有通過循環運行它佔據多個職位。這是if/while來的地方。 'if'檢查帖子,'while'告訴它該做什麼',而'仍然有帖子帖子可以運行。參數傳遞給query_posts()中的查詢;就像你在原始代碼中一樣。 – ckaufman 2011-03-21 20:39:05

+0

就是這樣!萬分感謝。 – dadra 2011-03-22 00:03:27

+0

很高興我可以幫助@dadra,一定要關閉/接受您的問題爲'已回答' – ckaufman 2011-03-22 03:37:01