好吧,我想我可能有一个解决办法。我不知道这是否是实现这一目标的正确方法,但就目前而言,这似乎是唯一可行的方法。
add_filter(\'rewrite_rules_array\', \'mmp_rewrite_rules\');
function mmp_rewrite_rules($rules) {
$newRules = array();
$newRules[\'portfolio/(.+)/(.+?).html$\'] = \'index.php?project=$matches[2]\';
$newRules[\'portfolio/(.+)/?$\'] = \'index.php?project_category=$matches[1]\';
return array_merge($newRules, $rules);
}
add_filter(\'request\', \'mmp_rewrite_request\');
function mmp_rewrite_request($vars) {
if (isset($vars[\'project_category\'])) {
if (strpos($vars[\'project_category\'], \'/\') !== false) {
$categories = explode(\'/\', $vars[\'project_category\']);
$vars[\'project_category\'] = $categories[count($categories) - 1];
}
}
return $vars;
}