我的分页有问题。
我创建了一个分类模板“taxonomy-product_cat-sale.php”来显示正在销售的产品。
一切正常,但是当我点击下一页(mysite.com/sale/page/2/)时,我重定向到 404 页面。
我跟着这个答案https://wordpress.stackexchange.com/a/304375
这是我的代码
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$ordering = WC()->query->get_catalog_ordering_args();
$ordering_explode = explode(' ', $ordering['orderby']);
$ordering['orderby'] = array_shift($ordering_explode);
$ordering['orderby'] = stristr($ordering['orderby'], 'price') ? 'meta_value_num' : $ordering['orderby'];
$products_per_page = apply_filters('loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page());
$product_ids_on_sale = wc_get_product_ids_on_sale();
$args = array(
'status' => 'publish',
'include' => $product_ids_on_sale,
'stock_status' => 'instock',
'limit' => $products_per_page,
'page' => $paged,
'paginate' => true,
'orderby' => $ordering['orderby'],
'order' => $ordering['order'],
);
$query_results = wc_get_products( $args );
wc_set_loop_prop('current_page', $paged);
wc_set_loop_prop('is_paginated', wc_string_to_bool(true));
wc_set_loop_prop('page_template', get_page_template_slug());
wc_set_loop_prop('per_page', $products_per_page);
wc_set_loop_prop('total', $query_results->total);
wc_set_loop_prop('total_pages', $query_results->max_num_pages);
有任何想法吗?