在循环中只显示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