【发布时间】:2019-08-16 21:38:18
【问题描述】:
分页不适用于 WP 的单页。
在下面的代码中,除了分页在下一页显示相同的内容之外,一切看起来都很好。
我尝试了在互联网上找到的所有可能的解决方案,但都没有奏效。我对 WP 和 php 比较陌生,所以如果你能查明可能是错误的代码,那将非常有帮助。
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged'
) : 1;
$args = array(
'posts_per_page' => 3,
'paged' => $paged,
'post_type' => 'book',
'offset' => 1,
'tax_query' => array(
array(
'taxonomy' => 'news_cat',
'field' => 'slug',
'terms' => array( 'disney' )
),
),
);?>
<?php $the_query = new WP_Query( $args );
?>
<?php if ($the_query->have_posts()) ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<a href="<?php echo ('/test/'.get_the_ID()); ?> "ontouchstart="" >
<li>
<div>
<figure><img src="<?php the_field('thumb'); ?>" alt="">
</figure>
</div>
<span><em><?php the_field('category'); ?></em><?php the_field('date'); ?></span>
<p><?php the_title(); ?></p>
</li>
</a>
<?php endwhile; ?>
<?php $GLOBALS['wp_query']->max_num_pages = $the_query->max_num_pages;
$args = array (
'prev_text' => '',
'next_text' => '',
'show_all' => false,
'mid_size' => 1,
'type' => 'list'
);
the_posts_pagination($args);?>
我希望分页能够正常工作,而不是在所有页面上显示相同的内容。
如您所见,我想让分页仅在带有“迪士尼”蛞蝓的帖子上工作。
【问题讨论】:
标签: php wordpress pagination