[英]wordpress pagination page links showing 404 error
我正在尝试向产品添加分页,我得到了分页链接,例如“1,2 next>>”,但是当我单击该链接时,它显示找不到页面。
$args = array( 'post_type' => 'product','product_cat' => 'clothing','posts_per_page' => '1', 'order' => 'DESC','paged' => $paged );
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
echo $product->get_regular_price();
endwhile;
$total_pages = $loop->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '/page/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => __('« prev'),
'next_text' => __('next »'),
));
}
wp_reset_postdata();
}
我认为您应该将格式更改为:
'format' => '?paged=%#%',
因为当前的“格式”(如果基础是正确的)给你例如https://yourwpwebsite.com/basepage/page/1
但它应该是https://yourwpwebsite.com/basepage?page=1
所以它仍然是同一页面,但在 URL 中传递了页面数据
我不确定当前的“基础”是否正确,但您也可以尝试将其更改为:
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
echo $product->get_regular_price();
endwhile;
$total_pages = $loop->max_num_pages;
$big = 999999999; // need an unlikely integer
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => __('« prev'),
'next_text' => __('next »'),
));
}
wp_reset_postdata();
}
试试这个,如果它不起作用,请提供更多详细信息和当前 HTML output。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.