How to display sub categories in Wordpress?

Should hierarchical sub-categories be used for posts? Why or why not?

  • I'm trying to get my head around category strategy and when it makes sense to use parent/sub-category relationships and how that affects what's displayed on archive pages. There are times when it seems to make sense solely for the purpose of organization, but I'm unclear as to exactly how WordPress treats an item that's in a sub-category vs. an item in both the parent and a sub-category.

  • Answer:

    The hierarchy is solely for category display purposes, it doesn't have any effect on posts. Posts treat categories as flat, regardless. That is to say if you have a hierarchy like this: - Main -- Sub Then a post in "Sub" is not automatically in "Main" as well. Posts are assigned to categories independently. However, as I have just learned, Category Archive pages will, by default, show post in children categories of the category being queried for. So a /category/main query on the site would indeed show the post in "Sub" there. If this is undesirable, you'd need to make your category archive page template do a custom query using "category__in" instead of "cat".

Samuel Wood at Quora Visit the source

Was this solution helpful to you?

Other answers

I've come to view hierarchical taxonomies (of which categories are one type of taxonomy) as being something that should be used very sparingly. I believe hierarchical categories were added prior to the inclusion of tags although I could have my WordPress history wrong. I'd far prefer to see tags be use for sub classification than subcategories. In general I think hierarchical categories should be limited to cases where there is no subjectivity in the classification (i.e. male/female, list of US States, etc.) and where it makes no sense for those classifications to be a subcategory of another category i.e. if categories are "Person", "Company", "Government Agency" then "Male/Female" only applies to "Person" and not "Company" or "Government Agency."  OTOH, if your hierarchical categorization is merely for exposing multi-segment URLs to filter your content and you use both single level categories and also tags, well, may God help you then. (or just write a plugin to route the URLs. :)

Mike Schinkel

I'm with Mike on this. Categorisation is one of the hardest things to get right on any website of depth. Making the actual categorisation more complex just lends itself to confusing everyone.

Robin Jennings

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.