[英]How to maintain separate permalink structure for specific category posts in wordpress
Hi Currently in our wordpress our default permalink structure is 嗨目前在wordpress中我们的默认永久链接结构是
abc.com/%postname%-%post_id%.html
But for specific category I want different permalink structure Ex: for Photos Category i want url structure as 但对于特定类别我想要不同的永久链接结构Ex:对于照片类别我想要url结构为
abc.com/%post_id%.html
Current i am using the following code But it is not working 目前我正在使用以下代码但它无法正常工作
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 == "Photos" ) {
$permalink = home_url('/'.$post->ID .'.html' );
}
return $permalink;
}
But i am not getting different permalink structure for specific category posts. 但我没有得到特定类别帖子的不同永久链接结构。 Please help me. 请帮我。
Posts must have a non-numeric slug because slug is an unique identifier. 帖子必须有非数字slug,因为slug是唯一标识符。
So please use %post_id% in conjunction with other text. 因此,请将%post_id%与其他文字结合使用。 That will surely work. 这肯定会奏效。
The custom permalink url like abc.com/%post_id%.html for specific category post is not possible and the same topic is discussed on https://wordpress.org/support/topic/post_id-only-permalink-comes-with-date-and-death-links . 无法使用abc.com/%post_id%.html等特定类别帖子的自定义永久链接网址,并在https://wordpress.org/support/topic/post_id-only-permalink-comes-with-上讨论相同的主题日期和死亡链接 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.