add_rewrite_rule() parent/child/child 页面出现问题

add_rewrite_rule() issue with parent/child/child page

我有一个 parent/child 和另一个 parent/child/child 页面。我有两个页面的单独页面模板和以下 add_rewrite_rule() 代码:

add_rewrite_rule( '^user/dashboard/([^/]*)/?’, 'index.php?pagename=user/dashboard&profile=$matches[1]', 'top' );

add_rewrite_rule( '^user/dashboard/billing/([^/]*)/?’, 'index.php?pagename='user/dashboard/billing&profile=$matches[1]', 'top' );

第一个(即 parent/child)工作正常,但第二个(即 parent/child/child)不工作。意思是当我转到 parent/child/child 页面时,它使用的是 parent/child 页面的模板,而不是分配给自己的模板。

如果我注释掉第一行 add_rewrite_rule() ,它会按预期工作。好像第一个覆盖了第二个。

我已经尝试通过转到设置 > 永久链接手动刷新重写规则。

我什至尝试更改重写规则的顺序,即我尝试在 [=35= 之前注册 parent/child/child 路径] 规则,然后手动刷新规则。但这也无济于事。

感谢任何帮助。

你需要改变顺序,首先是更具体的add_rewrite_rule,然后是一般的,试试这个

   add_rewrite_rule( '^user/dashboard/billing/([^/]*)/?', 'index.php?pagename=user/dashboard/billing&profile=$matches[1]', 'top' );
   add_rewrite_rule( '^user/dashboard/([^/]*)/?', 'index.php?pagename=user/dashboard&profile=$matches[1]', 'top' );

更改后,您必须在设置中打开off/on永久链接以清除缓存。