我找到了WP\\U查询问题的解决方案。我缺少的是偏移量(我没有意识到在处理自定义查询时需要设置偏移量)。
第一:获取当前页面
// If the query var is set use it; otherwise, initialize it to one.
$page = get_query_var( \'paged\' ) ? get_query_var( \'paged\' ) : 1;
第二:编写查询
// First, initialize how many posts to render per page
$display_count = 2;
// Next, get the current page
$page = get_query_var( \'paged\' ) ? get_query_var( \'paged\' ) : 1;
// After that, calculate the offset
$offset = ( $page - 1 ) * $display_count;
// Finally, we\'ll set the query arguments and instantiate WP_Query
$query_args = array(
\'post_type\' => \'post\',
\'orderby\' => \'date\',
\'order\' => \'desc\',
\'number\' => $display_count,
\'page\' => $page,
\'offset\' => $offset
);
$custom_query = new WP_Query ( $query_args );
/*
* Use your query here. Remember that if you make a call to $custom->the_post()
* you\'ll need to reset the post data after the loop by calling wp_reset_postdata().
*/
资料来源:
Tom McFarlin