【发布时间】:2019-04-03 08:21:34
【问题描述】:
看了这么多文章,没有找到答案。
我在类别中的自定义产品循环:
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
global $post;
$args = array(
'posts_per_page' => 6,
'product_cat' => $post->post_name, // **The father category**
'post_type' => 'product',
'paged' => $paged,
'page' => $page,
'pagination' => true
);
$loop = new WP_Query( $args );
echo $loop->request;
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
?>
////////////////// product info//////////////
<?php endwhile;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $loop->max_num_pages
) );
} else {
echo __( 'No products found' );
}
wp_reset_postdata();
在分类页面我有相同的链接:
http://localhost:3000/product-category/cats/videocard/
分页链接: http://localhost:3000/product-category/cats/videocard/page/2/
但我上面有 404。
我的永久链接设置: enter image description here
我的“阅读”设置: enter image description here
我做错了什么?
【问题讨论】:
-
我将此规则添加到 .htaccess RewriteRule ^page/([^/]*)/$ /?page=$1 [L] 如果我转到 localhost:3000/product-category/cats/videocard/?page=2 我会看到第 2 页。如何我可以在 localhost:3000/product-category/cats/videocard/page/2 中获得相同的结果吗?
标签: php wordpress woocommerce pagination