我用过Wordpresspaginate_links()
在自定义帖子类型的自定义存档模板上构建分页器。我的网站使用永久链接:
<?php echo paginate_links(array(
\'base\' => get_pagenum_link(1) . \'%_%\',
\'current\' => max(1, get_query_var(\'paged\')),
\'format\' => \'page/%#%\',
\'total\' => $wp_query->max_num_pages,
)); ?>
在我尝试添加查询字符串变量以在分页器回显时构建自定义搜索字符串之前,这一切都很正常:
.../entries?post_type=entry&s=testpage/1
.../entries?post_type=entry&s=testpage/2
而不是:
.../entries/page/1?post_type=entry&s=test
.../entries/page/2?post_type=entry&s=test
等等。。。如何获取格式正确的URL?
最合适的回答,由SO网友:benedict_w 整理而成
查询字符串似乎来自对的基参数调用get_pagenum_link()
因此,我删除了查询字符串组件,并使用“add\\u args”重新添加它。像这样:
<?php echo paginate_links(array(
\'base\' => preg_replace(\'/\\?.*/\', \'/\', get_pagenum_link(1)) . \'%_%\',
\'current\' => max(1, get_query_var(\'paged\')),
\'format\' => \'page/%#%\',
\'total\' => $wp_query->max_num_pages,
\'add_args\' => array(
\'s\' => get_query_var(\'s\'),
\'post_type\' => get_query_var(\'post_type\'),
)
)); ?>