我建立了一个 Wordpress 网站,其中有一个名为“Nieuwsberichten”的页面。 网址看起来像
https://www.example.com/newsitems
此页面是动态的,我需要一个名为“news_page”的额外参数
https://www.example.com/news/?news_page=recent
上面的 URL 不友好,因此我为此创建了一个重写规则,并添加了变量“news_page”。
functions.php
function add_query_vars($vars){
$vars[] = 'news_page';
return $vars;
}
add_filter( 'query_vars', 'add_query_vars', 10, 1 );
function rewrite_paged(){
add_rewrite_rule('^nieuwsberichten/([0-9]+)/?', 'nieuwsberichten?news_page=$matches[1]', 'top');
}
add_action('init', 'rewrite_paged');
此后我刷新了永久链接 菜单 -> 设置 -> 永久链接 -> 保存
如果我浏览到
https://www.example.com/news/recent/
它将重定向到
https://www.example.com/newsmessages/
我的代码中遗漏了什么?
希望有人能帮我解决这个问题
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号