如果为一个站点添加重写规则,那么在订单部分添加重写规则非常容易。如果您想创建一个通用的解决方案,该解决方案适用于具有各种permalink结构和自定义分类的所有安装,那么这将更加困难。
这个简短的示例适用于WordPress 3.1的基本安装,没有额外的自定义分类法。我使用orderby
防止与现有帖子名称冲突的前缀:
add_action( \'init\', \'wpse13483_init\' );
function wpse13483_init()
{
add_rewrite_rule( \'category/(.+?)/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$\', \'index.php?category_name=$matches[1]&paged=$matches[4]&orderby=$matches[2]\', \'top\' );
add_rewrite_rule( \'tag/([^/]+)/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$\', \'index.php?tag=$matches[1]&paged=$matches[4]&orderby=$matches[2]\', \'top\' );
add_rewrite_rule( \'type/([^/]+)/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$\', \'index.php?post_format=$matches[1]&paged=$matches[4]&orderby=$matches[2]\', \'top\' );
add_rewrite_rule( \'author/([^/]+)/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$\', \'index.php?author_name=$matches[1]&paged=$matches[4]&orderby=$matches[2]\', \'top\' );
add_rewrite_rule( \'([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$\', \'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[6]&orderby=$matches[4]\', \'top\' );
add_rewrite_rule( \'([0-9]{4})/([0-9]{1,2})/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$\', \'index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[5]&orderby=$matches[3]\', \'top\' );
add_rewrite_rule( \'([0-9]{4})/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$\', \'index.php?year=$matches[1]&paged=$matches[4]&orderby=$matches[2]\', \'top\' );
}