我做了大量的挖掘工作,我想出了这段代码来解决这个问题,并将“.html”添加到页面、类别和标记中。permalink设置负责POST。
function hpct_page_rewrite($rules) {
foreach ($rules as $key => $value) {
$newrules[str_replace(\'/?\', \'.html\', $key)] = $value;
}
return $newrules;
}
function hpct_page_link($link) {
return $link . \'.html\';
}
function hpct_category_rewrite($rules) {
foreach ($rules as $key => $value) {
$newrules[str_replace(\'/?\', \'.html\', $key)] = $value;
}
return $newrules;
}
function hpct_category_link($link) {
return str_replace(\'category/\', \'category-\', $link) . \'.html\';
}
function hpct_tag_rewrite($rules) {
foreach ( $rules as $key => $value ) {
$newrules[str_replace(\'/?\', \'.html\', $key)] = $value;
}
return $newrules;
}
function hpct_tag_link($link) {
return str_replace(\'tag/\', \'tag-\', $link) . \'.html\';
}
add_filter(\'page_rewrite_rules\', \'hpct_page_rewrite\', 3);
add_filter(\'page_link\', \'hpct_page_link\', 1);
add_filter(\'category_rewrite_rules\', \'hpct_category_rewrite\', 3);
add_filter(\'category_link\', \'hpct_category_link\', 1);
add_filter(\'tag_rewrite_rules\', \'hpct_tag_rewrite\', 3);
add_filter(\'tag_link\', \'hpct_tag_link\', 1);
是的,它也是硬编码的,我最终会处理好的。但至少我可以在WordPress中做到这一点。