在循環中只顯示2個帖子的最佳方式是什麼?WordPress的循環:只顯示2個帖子
<?php
$i = 1;
while (have_posts()):
if ($i == 3)
{
break;
}
the_post();
$i++;
endwhile;
?>
有什麼更「美」嗎?
在循環中只顯示2個帖子的最佳方式是什麼?WordPress的循環:只顯示2個帖子
<?php
$i = 1;
while (have_posts()):
if ($i == 3)
{
break;
}
the_post();
$i++;
endwhile;
?>
有什麼更「美」嗎?
query_posts('posts_per_page=2');
循環之前。從文檔頁面
摘錄:
query_posts()可以用來顯示效果比那些通常在特定的URL顯示不同的崗位。
試試這個:
<?php
// Printing post number 1 and 2
for($i = 1; $i < 3; $i++){
the_post();
}
?>
for($i = 0; $i < 2; ++$i) {
post_here();
}
可以使用WP_Query類,以避免與您的自定義環
$results = new WP_Query('posts_per_page');
if ($results->have-posts()) {
while ($results->have_posts()) {
$results->the_post();
the_title();
}
}
unset($results);
OMG,有什麼簡單的事情混合全局的帖子!謝謝。 – thom 2011-03-19 16:05:47