我改变了http://domain.com/%postname%/ 到http://domain.com/news/%postname%/ 使用此处提供的答案:Add a URL prefix to permalinks of one category of posts only. 但我对新闻本身的分类有问题。如何使此功能适用于子类别
仅向帖子的新闻类别和子类别的固定链接添加URL前缀
1 个回复
SO网友:Dharmishtha Patel
add_action( \'init\', \'wpa_category_base\' );
function wpa_category_base() {
// Remember to flush the rules once manually after you added this code!
add_rewrite_rule(
// The regex to match the incoming URL
\'news/([^/]+)/([^/]+)/([^/]+)(/[0-9]+)?/?$\',
// The resulting internal URL
\'index.php?category_name=$matches[1]/$matches[2]&name=$matches[3]&paged=$matches[4]\',
// Add the rule to the top of the rewrite list
\'top\' );
}
自定义永久链接结构:/media/%category%/%postname%/类别库:。为我工作,WordPress 3.4.1,没有任何相关插件。
尝试
add_action( \'init\', \'wpa_category_base\' );
function wp_category_base() {
// Remember to flush the rules once manually after you added this code!
add_rewrite_rule(
// The regex to match the incoming URL
\'news/([^/]+)/([^/]+)/([^/][^f][^e][^e][^d]+)(/[0-9]+)?/?$\', //here my changes to exclude \'feed\'
// The resulting internal URL
\'index.php?category_name=$matches[1]/$matches[2]&name=$matches[3]&paged=$matches[4]\',
// Add the rule to the top of the rewrite list
\'top\' );
}
结束