I’ve used WordPress for years as a content admin but I am new to PHP development (am fine with HTML/CSS). From Googling about and experimenting I believe that what I want to achieve isn’t standard WordPress functionality, but it is so commonplace on sites I’m surprised I haven’t found a solution yet.
I have a Custom Post Type of ‘recipes’ and a Custom Taxonomy of ‘recipe_type’. I’m able to see a list of posts at /taxonomy/term/ , but the /taxonomy/ page produces a 404. I am using the Pods plugin to create these (and all custom fields) but there’s nothing being created that isn’t core WP i.e. no pods-specific stuff.
I would like to have a page at /taxonomy/ that lists the taxonomy terms e.g. ‘vegan’, ‘vegetarian’, etc. The user can then link through to the term pages through these.
I see this as the familiar setup on ecommerce sites where you’ll have /products/ as a landing page and then /products/product-type/ as the lists of items, for example /products/cameras/ or /products/televisions/ .
I have tried to set this up by having a taxonomy-recipe_type.php template and archive-recipes.php template concurrently. The archive lists the terms in a grid and the taxonomy template lists the posts correctly. However, I run into several issues:
- Permalink issues - archive appears at /recipes/ but the taxonomy pages appear at /recipe-type/.
- Enabling rewrite fixes this but then the posts don’t appear (404).
- This isn’t a very DRY approach - I’m having to use two templates just to get this setup, and I’d like to repeat this setup for other CPTs and Taxonomies.
This seems a very common thing to setup but I’m just running out of luck. How can I create a taxonomy template that checks if the user is currently on the root taxonomy page (i.e. example.com/taxonomy/) and then display a list of terms. Else, if they’re on a term page (i.e. example.com/taxonomy/term/) display the list of posts?
Thanks in advance!