我最終通過用代字符(〜)預先輸入用戶的URL來完成此操作。重寫代碼如下:
// Uncomment only when new rewrites have been made
//add_filter('init', 'wds_flush');
// Leave uncommented
add_filter('rewrite_rules_array', 'wds_user_rewrite');
add_filter('query_vars','wds_query_vars');
function wds_flush()
{
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
function wds_user_rewrite($rules)
{
global $wp_rewrite;
$newRule = array(
'^~(.+)$' => 'index.php?pagename=user&uid=$matches[1]&act=show',
);
$newRules = $newRule + $rules;
return $newRules;
}
function wds_query_vars($vars)
{
array_push($vars, 'uid');
array_push($vars, 'act');
return $vars;
}
將不會有每個用戶的頁面。相反,只有一個頁面根據在URL中傳遞的用戶名收集內容。我想簡單地通過example.com/username來清除它(但只有在用戶存在的情況下才去那裏,否則只需處理在wp-admin中設置的永久鏈接)。爲了清晰起見,編輯了主要帖子,感謝您的幫助! – 2010-09-16 03:49:54