我有这个网址:
example.com/parent /
我已经在WordPress中创建了此页面,它使用了模板page-parent.php
有没有一种方法可以在使用此模板的情况下动态创建页面,而无需向WordPress添加页面,我知道我可以使用查询变量
例如example.com/parent/?q=17
但是我想知道是否可以拥有
example.com/parent/child1 /
example.com/parent/child2 /
无需将它们添加为'Pages'
并使用父模板。
答案 0 :(得分:0)
<?php /* Template Name: Example Template */ ?>
的顶部,并使用您要使用的任何名称。答案 1 :(得分:0)
感谢@cabrerahector-我一直在寻找add_rewrite_rule(),我只需要添加这些功能并刷新我的永久链接。
function custom_rewrite_tag() {
add_rewrite_tag('%child%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);
function custom_rewrite_rule() {
add_rewrite_rule('^parent/([^/]*)/?','index.php?page_id=207&child=$matches[1]','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);
答案 2 :(得分:0)
当前,您的page-parent.php是特定于该页面的模板(由于页面文件与文件名匹配)。但是,您可以将现有的page-parent.php文件转换为可用于任意数量页面的模板。