1
为什么http://localhost/wp/?paged=2和更旧版本无法在wp_query中工作?为什么页面2不能在wp查询中工作
我有超过15个帖子的“自定义帖子类型”的电影和系列。 它在前端分成两页,但当我按下较旧的帖子时,页面仍然是第一页。
这里是我的index.php循环代码:
<?php
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$query_args = array(
'post_type' => array('post','series','movie'),
'posts_per_page' => 10,
'paged' => $paged
);
$the_query = new WP_Query($query_args);
?>
<?php if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>
<h1><?php the_title();?></h1>
<?php endwhile; ?>
<div class="col-md-12">
<?php if ($the_query->max_num_pages > 1) { // check if the max number of pages is greater than 1 ?>
<nav class="prev-next-posts">
<div class="prev-posts-link">
<?php echo get_next_posts_link('Older Entries', $the_query->max_num_pages); // display older posts link ?>
</div>
<div class="next-posts-link">
<?php echo get_previous_posts_link('Newer Entries'); // display newer posts link ?>
</div>
</nav>
<?php } ?>
</div>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<article>
<h1>Sorry...</h1>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
</article>
<?php endif; ?>
只要我的回答不是正确的答案,你可能需要确认你的答案是正确的,所以在将来如果有任何访客来到你的问题,他可以很容易地得到解决方案 – hassan