在帖子 URL 中显示类别和子类别 - Wordpress

时间:2021-02-24 08:43:58

标签: wordpress

我需要自定义我的帖子 URL (wordpress)。

我使用父类别和子类别。

如果我从子类别发布帖子,则 URL 为: domain.be/category/subcategory/post-title

但是如果我选择子类别和父类别,网址是: domain.be/category/post-title

我需要,如果我选择两者,带有 cat 和 subcat 的 url。

在 Wordpress BO > 设置 > 永久链接:

enter image description here

我不想使用插件

1 个答案:

答案 0 :(得分:0)

首先,在修改 url 永久链接结构时,最好使用 Wordpress flush_rewrite_rules() 函数刷新重写规则。

<块引用>

删除重写规则,然后重新创建重写规则。


您实际上是在正确的轨道上,确实需要在自定义永久链接结构中使用 /%category%/%postname%/

为了本示例的目的,让我们声明两个类别,一个父类和一个子类,FruitsTomatoes

Fruits
└── Tomatoes

Wordpress 使用分层字母顺序来选择将在 url 永久链接结构中使用的类别。 默认情况下,Wordpress 每个级别不能显示超过 1 个类别。

<头>
行为 说明
可能 例如:domain.com/parent/child/grand-child/my-first-post/
不可能 例如:domain.com/parent-1/parent-2/my-first-post/

如果我们希望我们的网址为 domain.com/fruits/my-first-post/,我们需要至少选择 fruits 类别。

如果我们希望我们的网址为 domain.com/fruits/tomatoes/my-first-post/,我们需要选择 tomatoes 类别

最后,您只需要取消选择与您的子类别相关联的顶级类别,就可以了。

相关问题