存储您的new WP_Query()
在变量中,全球化$wp_query
移动$wp_query
在您的new WP_Query()
生成将变量传递给$wp_query
, 非new WP_Query()
调用自身例如。
<?php
// Custom query args
$press_query_args = array(
\'post_type\' => \'press\',
\'orderby\' => \'post_date\',
//\'showposts\' => \'10\',
\'posts_per_page\' => $paged,
);
// Custom query
$press_query = new WP_Query( $press_query_args );
// Globalize $wp_query
global $wp_query;
// Swap-hack
$temp = $wp_query;
$wp_query= null;
$wp_query = $press_query;
// Output custom loop
while ($press_query->have_posts()) : $press_query->the_post();
// EVERYTHING FROM HERE BELOW SHOULD BE THE SAME,
// THOUGH I\'VE CLEANED IT UP A BIT
// (MAINLY, REMOVING THE CLOSE/OPEN PHP TAG COMBOS)
// The following determines what the post format is and shows the correct file accordingly
$format = get_post_format();
get_template_part( \'/lib/includes/post-formats/\'.$format );
if($format == \'\')
get_template_part( \'/lib/includes/post-formats/standard\' );
endwhile;
if (function_exists("pagination")) {pagination($additional_loop->max_num_pages);}
$wp_query = null; $wp_query = $temp;
?>
EDIT
回复:每页的分页/张贴问题:
Hi chip,谢谢你,但这会产生一些奇怪的行为,在第一页你会看到10篇文章,然后从第1-7页分页,但在第二页你会看到第一页上出现的前两篇文章,分页编号从2-35变为2-35
我怀疑问题出在这里:
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 10;
与此数组参数结合使用:
$wp_query->query(array(
\'posts_per_page\' => $paged,
));
What happens if you remove $paged
and the \'posts_per_page\'
array argument?
此外:
分页(1-7 vs 2-35)问题可能与每页文章问题(尽管可能相关)是分开的。尝试使用previous_posts_link()
和next_posts_link()
, 只是为了隔离每页的帖子。