我正在跟踪WP Example. 我知道我的重写规则正在添加到wordpress中,所以我只需要修复实际的规则。下面是我当前的代码:
add_filter(\'rewrite_rules_array\',\'mcs_TextbookRewriteRules\');
add_filter(\'query_vars\',\'mcs_insertTextbookQueryVars\');
// Adding a new rule
function mcs_TextbookRewriteRules($rules) {
$newrules = array();
$newrules[\'textbook/(cantonese|mandarin)/([C|M]K?[0-9]+)/([0-9]+)$\'] = \'index.php?pagename=textbook/$matches[1]/?cls=$matches[2]&ch=$matches[3]\';
//$newrules[\'textbook/(cantonese|mandarin)/([C|M]K?[0-9]+)/([0-9]+)$\'] = \'textbook/$matches[1]/index.php?cls=$matches[2]&ch=$matches[3]\';
return $newrules + $rules;
}
// Adding the id var so that WP recognizes it
function mcs_insertTextbookQueryVars($vars) {
array_push($vars, \'cls\');
array_push($vars, \'ch\');
return $vars;
}
我想映射
http://localhost/wordpress/textbook/cantonese/CK1/6
到
http://localhost/wordpress/textbook/cantonese/?cls=CK1&ch=6