感谢这篇文章的提醒:http://zagar.biz/2011/wordpress-creating-custom-permalinks/
我的最终代码是这样的:
In the theme\'s functions.php file
add_filter(\'rewrite_rules_array\',\'mycode_add_rewrite_rules\');
// Add all rewrite rules here
// ** Remember to Flush Rewrite rules when adding new rules.
// this is done by visiting the Settings > Permalinks in WP admin.
function mycode_add_rewrite_rules($rules){
$newrules = array();
$newrules[\'tal-dia-como-hoy/([^/]+)/([^/]+)/?\'] = \'index.php?pagename=tal-dia-como-hoy&dia=$matches[1]&mes=$matches[2]\';
return $newrules + $rules;
}
add_filter(\'query_vars\',\'mycode_add_rewrite_query_vars\');
// Add all slugs so that WP recognizes it
function mycode_add_rewrite_query_vars($vars){
array_push($vars, \'dia\');
array_push($vars, \'mes\');
return $vars;
}
然后,在
the page I created. 这只是一个普通的wordpress页面,不是模板或类似的东西
global $wp;
// connect to your external DB, etc...
if($wp->query_vars["dia"]){
echo "Permalinks are working";
// load up your external data here and display single resource
// if the beard slug doesn\'t exist, redirect to 404
} else {
// load up whatever you want to display for the index version.
echo "Nothing shows up but it\'s working anyway";
}
我必须编辑页面,使其与我的全新permalinks保持一致。
这是我将用于此代码的页面:http://planeta-beisbol.com/tal-dia-como-hoy/19/04/
“04年19日”部分的意思是:4月19日
我希望这段代码对每个人都有用