我根据一些文档文章为“自定义帖子类型”实现了分页,但无法正常工作。
单击下一页后,我的URL在/ page / 2 /上更改,但是帖子仍然相同。
<div class="cpt-news">
<div class="row">
<?php
?>
<?php
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = array(
'post_type' => 'news',
'post_status'=>'publish',
'posts_per_page' => 4,
'paged' => $paged,
);
$the_query = new WP_Query($args);
if ( $the_query->have_posts() ):
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="col-12">
<div class="cpt-news-block mb-3">
<div class="row">
<div class="col-12 col-sm-6 col-lg-12 col-xl-6">
<a class="zoom-picture-hover" href="<?php the_permalink()?>">
<div class="cpt-news-block-image picture">
</div>
</a>
</div>
<div class="col-12 col-sm-6 col-lg-12 col-xl-6">
<h2 style="font-size: 20px;">
<a href="<?php the_permalink()?>">
<?php the_title()?>
</a>
</h2>
<p class="mb-3"><?php the_field('popis_inzeratu')?></p>
<a href="<?php the_permalink()?>" class="cpt-news-block-link link-read-more"> <?php
include get_stylesheet_directory() . '/assets/img/svg/icon_arrow.svg';
?>
<?php echo "More";?>
</a>
</div>
</div>
</div>
</div>
<?php endwhile;?>
<div class="">
<?php
echo paginate_links( array(
'format' => 'page/%#%',
'current' => $paged,
'total' => $the_query->max_num_pages,
'mid_size' => 2,
'prev_text' => __('« Prev Page'),
'next_text' => __('Next Page »')
) );
?>
</div>
<?php endif; ?>
</div>
</div>
我实施错了吗?我真的没有头绪,这可能很糟糕。
答案 0 :(得分:0)
检查注册自定义帖子类型的代码。查看将哪些参数传递给“ register_post_type ”。重写参数可能会对分页产生影响。
register_post_type( 'news', $args );
https://developer.wordpress.org/reference/functions/register_post_type/