下面的代码是其中一位评论员提到的,但它破坏了分页。请更正
<?php
include(TEMPLATEPATH. \'/includes/headline.php\'); rewind_posts();
if (have_posts())
{
echo \'<div class="gridrow clear">\';
while (have_posts()) : the_post();
global $post;
$query_string;
query_posts( $query_string .\'&posts_per_page=5\' );
include(TEMPLATEPATH. \'/includes/loop.php\');
$q = $wp_query->current_post;
$maxq = tj_current_postnum();
if($q < $maxq-1 && is_int(($q+1)/2)) echo \'</div><div class="gridrow clear">\';
$postcount++;
endwhile;
echo \'</div> <!--end .gridrow-->\';
} else {
include(TEMPLATEPATH. \'/includes/not-found.php\');
}
if ( $wp_query->max_num_pages > 1 ) tj_pagenavi();?>
最合适的回答,由SO网友:Hameedullah Khan 整理而成
你需要告诉Wordpress每页只能获得5篇帖子。执行此操作的参数是posts\\u per\\u page。在生成帖子之前,应该使用query\\u posts()函数,如下例所示。
<?php
// your includes and stuff
global $query_string;
query_posts( $query_string . \'&posts_per_page=5\' );
// now your have_posts
if ( have_posts() ) {
// list the posts
} else {
// not found msg here..
}
?>