Wordpress - Show parent category AND subcategory n

2020-02-28 04:18发布

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.

8条回答
我欲成王,谁敢阻挡
2楼-- · 2020-02-28 04:40

If use custom permalinks settings as %postname% only, it will make your url in the form of .../category/subcategory.

查看更多
爷、活的狠高调
3楼-- · 2020-02-28 04:42

To make this happen you need to make some change in permalinks

go to Settings->Permalinks then select custom structure and use this syntax " /%category%/%postname%/ "in the field

Now save the settings and you can see the post url's using its category name in the permalink

Hope it helps :)

查看更多
男人必须洒脱
4楼-- · 2020-02-28 04:44

Setting Settings->Permalinks->Category base to '%category%' should give you what you want. According to WP doc:

Nested sub-categories appear as nested directories in the URI

See http://codex.wordpress.org/Using_Permalinks.

查看更多
萌系小妹纸
5楼-- · 2020-02-28 04:46

The Permalinks settings should be like /%category%/%postname%/ ..

查看更多
放我归山
6楼-- · 2020-02-28 04:53

You should set hierarchical value to true when you are defining your taxonomy.

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

Then if you have a subcategory the url will be shown like this: http://example.com/taxonomy/parentCategory/subCategory/

I found this sloution here:

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

查看更多
在下西门庆
7楼-- · 2020-02-28 04:55

You can use WordPress plugin to remove 'category' from url http://wordpress.org/plugins/wp-no-category-base/ and then follow the instruction given by Maruti

查看更多
登录 后发表回答