简体   繁体   English

如何在wordpress中为特定类别帖子维护单独的永久链接结构

[英]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.

相关问题 Wordpress永久链接结构更改不适用于某些帖子 - Wordpress Permalink structure Change not working for some posts WordPress永久链接到特定博客文章,而不是当前URL - Wordpress Permalink to specific blog posts, not current URL Wordpress如何显示类别中的所有帖子,顶部带有特定标记的帖子 - Wordpress How to display all posts in category, with specific tag posts at top 如何在Wordpress中的特定页面上放置特定类别的帖子? - How to put specific category posts on specific pages in Wordpress? 如何在循环中在WordPress帖子上输出术语的永久链接? - How to output permalink for term on WordPress posts in loop? 如何将“项目”永久链接更改为Wordpress中帖子的类别 - How to change the 'Projects' permalink to the Category of the post in Wordpress PHP:如何在WordPress中使用自定义查询显示特定类别的帖子? - PHP: How to display posts of specific category using a custom query in WordPress? 如何显示所有帖子,但在wordpress上排除特定类别? - How do I show all posts but exclude a specific category on wordpress? WordPress:如何通过循环显示特定类别的帖子? - Wordpress: How to show posts from a specific category via the loop? 如何获取特定类别Wordpress的帖子的标题,图像和摘录 - How to get Title, Image and excerpt of posts of a specific category Wordpress
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM