无论如何,我无法理解为什么WP\\u Query会拉入所有帖子,而完全忽略posts_per_page
...我只想展示一个帖子。
<?php
$args = array(
\'post_type\' => \'post\',
\'orderby\' => \'date\',
\'order\' => \'ASC\',
\'posts_per_page\' => -1
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<div style="padding: 15px;">
<div class="grid_4 alpha">image</div>
<div class="grid_7 omega">
<?php the_excerpt(); ?>
</div>
</div>
<div style="clear: both;"></div>
<div style="height: 33px; background-color: #5ba4d8; position: relative;">
<div style="width: 300px; line-height: 33px;"><?php the_title(); ?></div>
<a href="" style="position: absolute; right: 0; top: 0;"><span class="nav-blog-next"></span></a>
</div>
<?php
endwhile;
// Reset Post Data
wp_reset_postdata();
?>
最合适的回答,由SO网友:Pontus Abrahamsson 整理而成
改变posts_per_page
到1
仅限,不限-1
.
像这样:\'posts_per_page\' => 1
-1
表示全部。