Step 1:
在WordPress仪表板中创建一个带有slug“profile”的页面。
Step 2
使用此功能注册
profileId
变量。
add_filter(\'query_vars\', \'wp233_query_vars\');
function wp233_query_vars( $query_vars ){
$query_vars[] = \'profileId\';
return $query_vars;
}
并向wordpress添加如下重写规则:
add_action( \'init\', \'wp233_add_rewrite_rules\' );
function wp233_add_rewrite_rules() {
add_rewrite_rule(
\'^profile/([^/]+)?$\',
\'index.php?pagename=profile&profileId=$matches[1]\',
\'top\');
}
Step 3
现在,您可以像这样访问查询变量:
http://yoursite.com/profile/xxxx/
现在,您应该能够通过挂接适当的操作来提取profileId
Example
add_action( \'template_redirect\', \'wp233_get_profile_id\' );
function wp233_get_profile_id() {
$profile_id = get_query_var( \'profileId\' );
if ( $profile_id ) {
// do some magic work. you now captured the profile id
// which was passed to url.com/profile/{ID}/ -> here.
}
}