我想知道的是,类别是否为“news”add/news event/before it。
更新:尚未生效。
多亏了@jas,我想这段代码可以做到,但我想我需要重写规则才能让它工作,我不擅长regex,所以我不知道怎么做,这是我迄今为止尝试过的。
add_filter( \'post_link\', \'custom_permalink\', 10, 3 );
function custom_permalink( $permalink, $post, $leavename ) {
// Get the categories for the post
$category = get_the_category($post->ID);
if ( !empty($category) && $category[0]->cat_name == "news" ) {
$permalink = trailingslashit( home_url(\'news-events/\' . $category. \'/\' . $post->post_name .\'/\' ) );
}
return $permalink;
}
function rewrite_rules( $wp_rewrite ) {
$new_rules[\'news-events/^news/([^/]+)/?\'] = \'index.php?name=$matches[1]\'; //change \'test\' to your category slug
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
return $wp_rewrite;
}
add_action(\'generate_rewrite_rules\', \'rewrite_rules\');
我的网站有这样的永久链接结构“site.com/en/postname1”,我有帖子类别“category1,category2,…”我想将我的帖子分类改为“site.com/en/category1/custom-text/postname1或site.com/en/category2/custom-text/postname2”。有可能吗?请帮帮我。