这可以通过以下方式实现adding rewrite rules.
第一add the query vars 将自定义值存储在我们的规则中:
function wpd_family_query_var( $query_vars ) {
$query_vars[] = \'wpd_family\';
$query_vars[] = \'wpd_members\';
return $query_vars;
}
add_filter( \'query_vars\', \'wpd_family_query_var\' );
接下来,添加规则以捕获两者
displaypage/family/
和
displaypage/family/members/
请求:
function wpd_add_family_rewrite_rules() {
add_rewrite_rule(
\'displaypage/([^/]+)/?$\',
\'index.php?pagename=displaypage&wpd_family=$matches[1]\',
\'top\'
);
add_rewrite_rule(
\'displaypage/([^/]+)/members/?$\',
\'index.php?pagename=displaypage&wpd_family=$matches[1]&wpd_members=true\',
\'top\'
);
}
add_action( \'init\', \'wpd_add_family_rewrite_rules\' );
别忘了,你必须
flush rewrite rules 更换后。
然后,您可以在任何地方访问查询变量的值after the parse_query
action 具有get_query_var()
:
if( $family = get_query_var( \'wpd_family\' ) ){
echo \'family: \' . $family;
}
if( $members = get_query_var( \'wpd_members\' ) ){
echo \'members: \' . $members;
}