admin管理员组文章数量:1387356
I'm trying to understand why my pagination gets 404 error on each page starts from second. Right now in Reading settings I've set Blog pages show at most
to 1.
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query = new WP_Query(
array(
'post_type' => 'behold_testimonials',
'orderby' => 'rand',
'paged' => $paged
)
);
if ($query->have_posts()):
while ($query->have_posts()): $query->the_post();
include( locate_template( '/elements/testimonials-thumbnail.php', false, false ) );
endwhile;
?>
<div class="l-pagination">
<?php
// kirki settings
$pagination_layout = get_theme_mod( 'posts_general__pagination-style', true );
if( 'layout-1' == $pagination_layout ) {
$pagination_layout_style = 'pagination-1';
} elseif( 'layout-2' == $pagination_layout ) {
$pagination_layout_style = 'pagination-2';
}
?>
<div class="c-pagination <?php echo $pagination_layout_style; ?>">
<?php
$total_pages = $query->max_num_pages;
echo paginate_links( array(
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
'format' => '?paged=%#%',
'total' => $total_pages,
'current' => max(1, get_query_var('paged')),
'prev_text' => __( '<i class="fas fa-caret-left"></i>', 'behold-standard' ),
'next_text' => __( '<i class="fas fa-caret-right"></i>', 'behold-standard' ),
) );
?>
</div>
</div>
<?php
wp_reset_postdata();
endif;
?>
Where is my mistake?
I'm trying to understand why my pagination gets 404 error on each page starts from second. Right now in Reading settings I've set Blog pages show at most
to 1.
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query = new WP_Query(
array(
'post_type' => 'behold_testimonials',
'orderby' => 'rand',
'paged' => $paged
)
);
if ($query->have_posts()):
while ($query->have_posts()): $query->the_post();
include( locate_template( '/elements/testimonials-thumbnail.php', false, false ) );
endwhile;
?>
<div class="l-pagination">
<?php
// kirki settings
$pagination_layout = get_theme_mod( 'posts_general__pagination-style', true );
if( 'layout-1' == $pagination_layout ) {
$pagination_layout_style = 'pagination-1';
} elseif( 'layout-2' == $pagination_layout ) {
$pagination_layout_style = 'pagination-2';
}
?>
<div class="c-pagination <?php echo $pagination_layout_style; ?>">
<?php
$total_pages = $query->max_num_pages;
echo paginate_links( array(
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
'format' => '?paged=%#%',
'total' => $total_pages,
'current' => max(1, get_query_var('paged')),
'prev_text' => __( '<i class="fas fa-caret-left"></i>', 'behold-standard' ),
'next_text' => __( '<i class="fas fa-caret-right"></i>', 'behold-standard' ),
) );
?>
</div>
</div>
<?php
wp_reset_postdata();
endif;
?>
Where is my mistake?
Share Improve this question asked Apr 27, 2020 at 11:11 D_PD_P 1531 gold badge3 silver badges12 bronze badges 3 |1 Answer
Reset to default 0The solution is that CPT should have 'has_archive'
set to 'true'
.
本文标签: Why my pagination gets 404
版权声明:本文标题:Why my pagination gets 404? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744526829a2610793.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
pre_get_posts
to modify it, don't throw it away and replace it with a brand new custom query. You'll be getting a 404 because the main query doesn't have that page, but your new query does. Is this a page template? Or is it that this is a sub-section that you're trying to give its own independent pagination? Note that random ordering is extremely heavy on the database, it's one of the heaviest slowest things you can do in a post query. It's always better to simulate randomness, e.g. choose a random date then ask for the closest post – Tom J Nowell ♦ Commented Apr 27, 2020 at 11:21