12

I'm having some trouble with Wordpress category/subcategory archive URLs.

For example, I want to be able to display this archive:
http://faroutmagazine.co.uk/wp/track-of-the-day while keeping its parent category in the URL, making it http://faroutmagazine.co.uk/wp/music/track-of-the-day

Previously, I was just getting a "This is embarrassing..." 404 message when accessing the /music/track-of-the-day URL (even though that's the one that was appearing in the View option under categories in the admin section of WP).

Now the View link in the admin area only shows me the /track-of-the-day URL, and this DOES display the category posts which is great, but I want it to include the parent category in the URL.

Is there anything I can do to the functions.php file or any plugins I can add to make this happen? Please bear in mind that there are multiple subcategory archives on this site, and they should all contain the parent category in the URL.

***UPDATE: I actually have just set everything up a different way now using Pages and showing category archives on pages as it's taking up too much time. Thanks for your answer though. People telling me to use %category%/%postname% as the permalink structure are incorrect - yes, this works for the POST urls but not for the archive category of the subcategory which is the problem I was actually looking for help with. If anyone can provide an answer, it would be appreciated, but I am using this workaround now as this was taking up way too much time trying to figure out.

4

8 回答 8

19

发生这种情况是因为您在编辑条目时从正确的选项复选框中选择了类别和子类别。在每个条目中仅选择子类别框,它将显示嵌套 URL。

于 2013-09-29T13:15:46.867 回答
5

要做到这一点,您需要对永久链接进行一些更改

转到Settings->Permalinks然后选择自定义结构并在字段中使用此语法“ /%category%/%postname%/

现在保存设置,您可以在永久链接中看到帖子网址使用其类别名称

希望能帮助到你 :)

于 2013-09-05T07:44:57.797 回答
3

实际上,分层子类别存档永久链接在 wordpress 中是默认的。

如果您在设置 > 永久链接中选择了“漂亮的永久链接”结构,/%postname%例如,那么类别和子类别存档 url 应默认为: yourdomain.com/category-base/category/sub-category/sub-sub-category

我在最近的一个 WP 项目中遇到了类似的问题,但是我使用了一个名为WP No Base Permalink的插件,以便在我的存档永久链接中摆脱我的类别和标签基础 slug。当我停用插件时,类别层次结构突然返回到我的存档永久链接(幸运的是,这个项目仍在开发中,否则我会遇到一些重大的 404 问题)。

我还没有找到/测试另一个插件来消除类别/标签基础 slug,它也将保留子/类别存档 url 中的层次结构,但事实证明我当前的项目不需要该功能。

相反,我使用基本 slugblog-articlesblog-tags标准类别和标签,以便将博客分类法与其他分类法区分开来。然后我使用插件类型为该帖子类型创建自定义帖子类型和自定义分类法。Types 插件在高级设置中有一个选项,可以将分层分类 url 设置为truefalse在创建自定义分类时。

最后,我找到了一个名为Remove Taxonomy Base Slug的插件,它有效地从分类档案 url 的基本 slug 中消除了默认分类术语。幸运的是,这不会干扰分层子/类别 URL,或标准标签和类别的基本 slug。

所以现在,我的博客类别/标签如下所示:

yourdomain.com/blog-articles/category/sub-category/ 或者yourdomain.com/blog-tags/tag/

我的自定义帖子类型类别/标签如下所示:

yourdomain.com/category/sub-category/或者yourdomain.com/tag/

呸!

我希望这有帮助!

于 2013-10-17T02:13:18.437 回答
3

定义分类时,应将分层值设置为 true。

'rewrite' => array('slug' => 'mySlug', 'hierarchical' => true),

然后,如果您有子类别,则 url 将显示如下: http ://example.com/taxonomy/parentCategory/subCategory/

我在这里找到了这个sloution:

https://wordpress.stackexchange.com/questions/155319/how-to-include-parent-terms-in-hierarchical-taxonomy-urls

于 2017-09-13T06:34:29.483 回答
2

将 Settings->Permalinks->Category base 设置为 '%category%' 应该可以满足您的需求。根据 WP 文档:

嵌套子类别在 URI 中显示为嵌套目录

请参阅http://codex.wordpress.org/Using_Permalinks

于 2013-09-04T22:40:21.130 回答
1

永久链接设置应该类似于 /%category%/%postname%/ ..

于 2013-09-06T05:56:48.090 回答
0

您可以使用 WordPress 插件从 url http://wordpress.org/plugins/wp-no-category-base/中删除“类别” ,然后按照 Maruti 给出的说明进行操作

于 2013-09-11T09:37:29.440 回答
0

如果仅将自定义永久链接设置用作 %postname%,它将使您的 url 采用 .../category/subcategory 的形式。

于 2013-09-11T07:08:22.253 回答