2011-03-19 65 views

回答

7

使用query_posts()

query_posts('posts_per_page=2'); 

循環之前。從文檔頁面

摘錄:

query_posts()可以用來顯示效果比那些通常在特定的URL顯示不同的崗位。

+0

OMG,有什麼簡單的事情混合全局的帖子!謝謝。 – thom 2011-03-19 16:05:47

0

試試這個:

<?php 
// Printing post number 1 and 2 
for($i = 1; $i < 3; $i++){ 
    the_post(); 
} 
?> 
0
for($i = 0; $i < 2; ++$i) { 
     post_here(); 
} 
0

可以使用WP_Query類,以避免與您的自定義環

$results = new WP_Query('posts_per_page'); 

if ($results->have-posts()) { 
    while ($results->have_posts()) { 
     $results->the_post(); 
     the_title(); 
    } 
} 

unset($results); 
相關問題