我创建了一个使用内置函数paginate_links的函数.
但是分页不正常,因为URL写错了.
我想要的URL看起来像这个domain.com/properties/page/2/?foo=bar
要输出的URL是domain.com/properties/?foo=bar/page/2/
这是我的代码
function paginate($max_num_pages) {
global $wp_query, $wp_rewrite;
$wp_query->query_vars['page'] > 1 ? $current = $wp_query->query_vars['page'] : $current = 1;
$pagination = array(
'base' => @add_query_arg('page','%#%'),
'format' => '',
'total' => $max_num_pages,
'current' => $current,
'show_all' => true,
'end_size' => 1,
'mid_size' => 2,
'prev_next' => True,
'prev_text' => __('« PrevIoUs'),
'next_text' => __('Next »'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => ''
);
if( $wp_rewrite->using_permalinks() )
$pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'page' );
if( !empty($wp_query->query_vars['s']) )
$pagination['add_args'] = array( 's' => get_query_var( 's' ) );
echo paginate_links( $pagination );
}
解决方法:
这是最终为我工作的东西.
我必须将$wp_query-> query_vars更改为paged并删除检查我是否使用perma链接的行if($wp_rewrite-> using_permalinks())$pagination [‘base’] = user_trailingslashit(trailingslashit(remove_query_arg) (‘s’,get_pagenum_link(1))).’page /%#%/’,’paged’);
function paginate($max_num_pages) {
global $wp_query, $wp_rewrite;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
$pagination = array(
'base' => @add_query_arg('paged','%#%'),
'format' => '',
'total' => $max_num_pages,
'current' => $current,
'show_all' => true,
'end_size' => 1,
'mid_size' => 2,
'prev_next' => True,
'prev_text' => __('« PrevIoUs'),
'next_text' => __('Next »'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => ''
);
//if ( $wp_rewrite->using_permalinks() ) $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );
if ( !empty($wp_query->query_vars['s']) ) $pagination['add_args'] = array( 's' => get_query_var( 's' ) );
echo paginate_links( $pagination );
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。