此代码为分页中的每个页面返回相同的帖子。
这是页面底部的“相关帖子”部分,因此是高级查询,不确定为什么分页不起作用。
<?php
$terms = get_the_terms( get_the_ID(), 'artwork_type' );
$term_list = wp_list_pluck( $terms, 'slug' );
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'artwork',
'paged' => $paged,
'post_status' => 'publish',
'post__not_in' => array( get_the_ID() ),
'tax_query' => array(
array(
'taxonomy' => 'artwork_type',
'field' => 'slug',
'terms' => $term_list
)
)
);
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query( $args );
while ($wp_query->have_posts()) :$wp_query->the_post(); ?>
<?php get_template_part( 'post', 'masonry' ); ?>
<?php endwhile; ?>
<nav class="art_nav">
<div class="next">
<?php next_posts_link('Next', $wp_query->max_num_pages); ?>
</div>
<div class="prev">
<?php previous_posts_link('Previous', $wp_query->max_num_pages); ?>
</div>
</nav>