Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 为自定义子页添加\u重写\u规则_Wordpress - Fatal编程技术网

Wordpress 为自定义子页添加\u重写\u规则

Wordpress 为自定义子页添加\u重写\u规则,wordpress,Wordpress,对于插件,我需要一个常规WordPress页面的子页面。正常页面位于 http://example.com/page 获得子页面 我使用的是重写规则: add_rewrite_rule( '([^/]+)/(subpage|subpage2|subpage3|subpage4)', 'index.php?pagename=$matches[1]&_mysubpage=$matches[2]', 'top'); 在我将页面移动到父页面之前,这一切正常: 或者如果我将页面设置为主页 ht

对于插件,我需要一个常规WordPress页面的子页面。正常页面位于

http://example.com/page
获得子页面

我使用的是重写规则:

add_rewrite_rule( '([^/]+)/(subpage|subpage2|subpage3|subpage4)', 'index.php?pagename=$matches[1]&_mysubpage=$matches[2]', 'top');
在我将页面移动到父页面之前,这一切正常:

或者如果我将页面设置为主页

http://example.com/subpage

我还需要哪一条添加重写规则?

我找到了一个可行的解决方案,但如果有人有更好的方法,请随意分享

1子页面

子页面上的页面名是page/subpage,因此初始的add\u rewrite\u规则变为

2.主页

对于主页,您需要页面ID和附加的“添加”“重写”规则

请注意,pagename get已替换为page_id

http://example.com/parentpage/page/subpage
http://example.com/subpage
add_rewrite_rule( '(.+)/(subpage|subpage2|subpage3|subpage4)', 'index.php?pagename=$matches[1]&_mysubpage=$matches[2]', 'top');
add_rewrite_rule( '^(subpage|subpage2|subpage3|subpage4)', 'index.php?page_id={YOUR_PAGE_ID}&_mysubpage=$matches[1]', 'top');