我也做过类似的事情。我有一个页面(country\\u tc),它使用一个自定义页面模板,可以动态生成请求国家的信息,也可以生成该国家的一系列子页面,例如。
/country/Egypt
(index.php?pagename=国家和国家TC=埃及)
/country/egypt/safety
(index.php?pagename=国家和国家TC=埃及/安全)
我使用page_rewrite_rules 用于重新写入。我没有时间审查你的代码,所以我会这样做:
在站点功能中plugin:
// allow WP to store querystring attribs for use in our pages
function tc_query_vars_filter($vars) {
$vars[] = \'department-team\';
$vars[] .= \'another-var\';
return $vars;
}
add_filter( \'query_vars\', \'tc_query_vars_filter\' );
function tc_rewrite_rules($rules) {
global $wp_rewrite;
$tc_rule = array(
// working example from my site
\'country/(.+)/?\' => \'index.php?pagename=\' . \'country\' . \'&countrytc=$matches[1]\',
// YOUR rule (not tested)
\'/([^/]*)/team\', \'index.php?pagename=YOURPAGENAME&department-team=$matches[1]\'
);
return array_merge($tc_rule, $rules);
}
add_filter(\'page_rewrite_rules\', \'tc_rewrite_rules\');
AFTER ACTIVATING PLUGIN YOU NEED TO RE-SAVE PERMALINKS ON DASHBOARD - THIS WILL FLUSH/UPDATE YOUR REWRITE RULES
执行其余代码
in your custom page 使用:
get_query_var(\'department-team\')
- 根据需要清理、验证并执行您的包含。