我有一个分页的搜索页面,显示了正确的页数,但是链接似乎正在转发到404页。
$paged = ( get_query_var( \'paged\' ) ) ? absint( get_query_var( \'paged\' ) ) : 1;
$search_args = array(
\'posts_per_page\' => 2,
\'s\' => get_search_query(),
\'post_status\' => \'publish\',
\'post_type\' => \'post\',
\'paged\' => $paged,
);
$search = new WP_Query($search_args);
$big = 999999999; // need an unlikely integer
$pagination_args = array(
\'base\' => str_replace($big, \'%#%\', esc_url(get_pagenum_link($big))),
\'format\' => \'?paged=%#%\',
\'current\' => max( 1, get_query_var(\'paged\') ),
\'mid_size\' => 2,
\'total\' => $search->max_num_pages
);
echo paginate_links($pagination_args);
任何关于为什么这些链接可能被破坏的帮助都将是巨大的帮助!
SO网友:Carl Johnston
评论中提供的答案:
global $wp_query;
$big = 999999999; // need an unlikely integer
$pagination_args = array(
\'base\' => str_replace($big, \'%#%\', esc_url(get_pagenum_link($big))),
\'format\' => \'?paged=%#%\',
\'current\' => max( 1, get_query_var(\'paged\') ),
\'mid_size\' => 1,
\'total\' => $wp_query->max_num_pages
);
if(have_posts()):
while(have_posts()):
the_post();
//individual search result
endwhile;
wp_reset_postdata();
echo paginate_links($pagination_args);
endif;