将此添加到主题的功能中。php,或put it in a plugin.
add_action( \'init\', \'wpse26388_rewrites_init\' );
function wpse26388_rewrites_init(){
add_rewrite_rule(
\'properties/([0-9]+)/?$\',
\'index.php?pagename=properties&property_id=$matches[1]\',
\'top\' );
}
add_filter( \'query_vars\', \'wpse26388_query_vars\' );
function wpse26388_query_vars( $query_vars ){
$query_vars[] = \'property_id\';
return $query_vars;
}
这将添加一个重写规则,将请求定向到
/properties/ pagename后面有数字的任意组合
properties, 使用查询变量
property_id 设置只需确保访问permalinks设置页面并保存以刷新重写规则,这样就会包含此新规则。
在您的page-properties.php 样板get_query_var(\'property_id\') 将返回属性id(如果已设置),如果未设置,则显示默认属性页。