next_posts_link
和previous_posts_link
, 与其他几个函数一样,使用一个名为$wp_query
. 此变量实际上是WP\\u查询对象的一个实例。然而,当您创建我们自己的WP\\u查询实例化时,您没有这个全局变量$wp_query
, 这就是分页无法工作的原因。
为了解决这个问题,你耍了个花招$wp_query
全球的
//save old query
$temp = $wp_query;
//clear $wp_query;
$wp_query= null;
//create a new instance
$wp_query = new WP_Query();
$args = array( \'post_type\' => \'artist\', \'posts_per_page\' => 3, \'paged\' => get_query_var( \'page\' ));
$wp_query->query($args);
while ( $wp_query->have_posts() ) : $wp_query->the_post();
echo \'<a class="artist" href="\'.get_post_permalink().\'">\';
echo \'<h3 class="artist-name">\'.get_the_title().\'</h3>\';
$attachments = attachments_get_attachments();
$total_attachments = count( $attachments );
for( $i=0; $i<$total_attachments; $i++ ) {
$thumb = wp_get_attachment_image_src( $attachments[$i][\'id\'], \'thumbnail\' );
echo \'<span class="thumb"><img src="\'.$thumb[0].\'" /></span>\';
}
echo \'</a>\';
endwhile;
echo \'</div>\';
next_posts_link();
//clear again
$wp_query = null;
//reset
$wp_query = $temp;