Im sure this is a pretty common question around here, so sorry if I am repeating a similar question already answered.

So I thought id have a dabble at creating my first Wordpress theme. I've created the template I would like to use for parent categories, now Im trying to work out how to create a template for sub-categories.

I've put all my parent category HTML in the categories.php file, should I be putting my sub-category HTML in the same file and adding some PHP to differentiate between parent and child categories (as this answer) or is there a different method I should use that I haven't uncovered yet.

Thanks in advance.

有帮助吗?

解决方案

It's simple, the specificity of the templating engine is handled by category name, regardless of any type of hierarchy in the category.

Therefore by targeting the category slug, you'll be able to theme it independent of the parent(s).

category-mysubcategory.php

Where mysubcategory is the slug of your category.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top