我的帖子分页在WordPress 5.5中不起作用,因此,我想重写分页的URL。I am using posts with pagination in the inner page with slug "post".
Current URL (The Pagination): domain.com/blog/2
I want to change the URL to: domain.com/blog/page/2
通过更改URL,帖子分页开始工作。我添加了jQuery代码,分页工作正常,但我如何在WordPress中做到这一点。
My code added in functions.php:
function my_pagination_rewrite() {
add_rewrite_rule(\'blog/page/?([0-9]{1,})/?$\', \'index.php?page=blog&paged=$matches[1]\', \'top\');
}
add_action(\'init\', \'my_pagination_rewrite\');
但这是行不通的。
I also tried the code using jQuery and it is working:
<script>
jQuery(\'.elementor-pagination\').find(\'a\').each(function() {
var url=jQuery(this).attr(\'href\');
var pieces = url.split("/");
var newhrf =window.location.origin+\'/blog/page/\'+pieces[4];
jQuery(this).attr(\'href\',newhrf);
});
</script>
jQuery代码正在运行,但我的代码在
functions.php
不工作。
非常感谢您的帮助。