wordpress分页页面链接显示404错误



我正在尝试将分页添加到产品中,我正在获得分页链接,例如'1,2next>gt;'但当我点击链接时,它显示找不到页面。

$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输出。

相关内容

最新更新