[英]How to fix the pagination showing page/1/
我正在使用paginate_links()
并且分页工作正常,但是我的问题是,当您返回第1页时,它显示(www.mysite.com/collections/page/1/)
应该何时发送回其父页面或主页www.mysite.com/collections/
www.mysite.com/collections
和www.mysite.com/collections/page/1/
是相同的页面,但URL结构不同,如何解决,所以页面1应该转到其主页并且没有page / 1的东西。
这是我正在使用的代码:
<?php
$first = ( $per_page * $paged ) - $per_page;
$last = min( $total, $per_page * $paged );
$current = isset( $paged ) ? $paged : wc_get_loop_prop( 'current_page' );
$base = isset( $base ) ? '' : esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) );
$format = isset( $format ) ? '?page=%#%' : '%#%';
echo paginate_links( apply_filters( 'woocommerce_pagination_args', array( // WPCS: XSS ok.
'base' => $base,
'format' => $format,
'add_args' => false,
'current' => max( 1, $current ),
'total' => ceil($total / $per_page),
'prev_text' => '←',
'next_text' => '→',
'type' => 'list',
'end_size' => 3,
'mid_size' => 3,
) ) );
?>
您可以使用jQuery更改它
if($('.pagination a:first').attr('href') === "http://yoursite.com/page/1")
{
$(".pagination a:first").attr("href", "http://yoursite.com/");
}
$(".pagination a:nth-child(2)").attr("href", "http://yoursite.com/");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.