I do know that this question has been asked before, but I'm writing because the solutions I have found didn't work.
So, I have a lot of posts with 'post_type' = 'post' that are filtered by a category taxonomy. The category taxonomy has some slugs that are hierarchical, while some of the others are not. I need to create a taxonomy template for each category.
So, for example, I have the following categories:
- Events
- Case Study (This has children categories such as Public, Health, etc) - All children will use the same template as the parent, in this case, the case study template
- Reports
Now, I've read on the documentation and on a lot of questions asked on stackexchange different ways of naming the taxonomy template file.
I've tried most of the naming of files including the following:
- taxonomy-category-{slug}.php
- taxonomy-category.php
- category-{slug}.php
- category-{ID}.php
- taxonomy.php
The post still uses the index.php template to display the post instead of any of the taxonomy created files.
In the wp_term_taxonomy table, I noticed the existence of multiple taxonomies with the same name (in this case category), all with a different ID, of course. The count on them is different, but adding all of them together don't add up to the amount of posts that I currently have. I'm not sure if this might be the issue (Maybe it doesn't know which taxonomy to use when there are multiple ones).
Anyone has any suggestions regarding this?
I do know that this question has been asked before, but I'm writing because the solutions I have found didn't work.
So, I have a lot of posts with 'post_type' = 'post' that are filtered by a category taxonomy. The category taxonomy has some slugs that are hierarchical, while some of the others are not. I need to create a taxonomy template for each category.
So, for example, I have the following categories:
- Events
- Case Study (This has children categories such as Public, Health, etc) - All children will use the same template as the parent, in this case, the case study template
- Reports
Now, I've read on the documentation and on a lot of questions asked on stackexchange different ways of naming the taxonomy template file.
I've tried most of the naming of files including the following:
- taxonomy-category-{slug}.php
- taxonomy-category.php
- category-{slug}.php
- category-{ID}.php
- taxonomy.php
The post still uses the index.php template to display the post instead of any of the taxonomy created files.
In the wp_term_taxonomy table, I noticed the existence of multiple taxonomies with the same name (in this case category), all with a different ID, of course. The count on them is different, but adding all of them together don't add up to the amount of posts that I currently have. I'm not sure if this might be the issue (Maybe it doesn't know which taxonomy to use when there are multiple ones).
Anyone has any suggestions regarding this?
Share Improve this question asked Mar 4, 2020 at 16:06 SebastianSebastian 31 bronze badge1 Answer
Reset to default 0The post won't use those templates because those aren't intended for posts. They're intended for the archive pages for those terms/categories/tags.
What's more, it doesn't make sense for it to work that way as it introduces ambiguity. Case in point, if I have category-red.php
and category-blue.php
, which template gets loaded if I visit a post that's in both red
and blue
categories?
Instead, take a look at the template hierarchy diagram, you'll very likely need to implement a check in your posts template yourself. Also consider adding a single.php
, and post.php
template to your theme