我正在尝试将我的自定义帖子分页,一旦达到每页帖子的限制,就可以有多个页面。最终目标是让url有/页=2等。我已经将测试限制为每页一篇文章(目前有两篇文章),但底部的新旧按钮没有显示出来?我做错了什么?
<div class="col-md-8">
<!-- set up or arguments for our custom query -->
<?php
$paged = ( get_query_var(\'page\') ) ? get_query_var(\'page\') : 1;
$query_args = array(
\'post_type\' => \'news\',
\'posts_per_page\' => 1,
\'paged\' => $paged
); ?>
<?php $news = new WP_Query(array(
\'post_type\' => \'news\'
)); ?>
<?php while($news->have_posts()) : $news->the_post(); ?>
<h2>
<a href="<?php the_permalink(); ?>"><?php the_title();?></a>
</h2>
<p class="lead">
<?php $author = get_the_author(); ?>
by <?php echo $author ?>
</p>
<p><i class="fa fa-clock-o"></i> Posted on <?php the_time(\'F j, Y\'); ?></p>
<hr>
<a href="#">
<?php if( get_field(\'image\') ): ?>
<img class="img-responsive img-hover" src="<?php the_field(\'image\'); ?>" alt="">
<?php endif; ?>
</a>
<hr>
<?php if(get_field(\'news_content\')): ?>
<p class="description"><?php echo get_field(\'news_content\'); ?></p>
<?php endif; ?>
<a class="btn btn-primary" href="<?php the_permalink(); ?>">Read More <i class="fa fa-angle-right"></i></a>
<hr>
<?php endwhile ?>
<!-- Pager -->
<?php if ($news->max_num_pages > 1) { ?>
<ul class="pager">
<li class="previous">
<a href="<?php echo get_next_posts_link( \'Older Entries\', $the_query->max_num_pages ); ?>">← Older</a>
</li>
<li class="next">
<a href="<?php echo get_previous_posts_link( \'Newer Entries\' ); ?>">Newer →</a>
</li>
</ul>
<?php } ?>
</div>