$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>custom post types - Display a grid of taxonomy terms at root taxonomy page|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

custom post types - Display a grid of taxonomy terms at root taxonomy page

matteradmin8PV0评论

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:

  1. Permalink issues - archive appears at /recipes/ but the taxonomy pages appear at /recipe-type/.
  2. Enabling rewrite fixes this but then the posts don’t appear (404).
  3. 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/taxonomy/) and then display a list of terms. Else, if they’re on a term page (i.e. example/taxonomy/term/) display the list of posts?

Thanks in advance!

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:

  1. Permalink issues - archive appears at /recipes/ but the taxonomy pages appear at /recipe-type/.
  2. Enabling rewrite fixes this but then the posts don’t appear (404).
  3. 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/taxonomy/) and then display a list of terms. Else, if they’re on a term page (i.e. example/taxonomy/term/) display the list of posts?

Thanks in advance!

Share Improve this question asked Jan 30, 2019 at 18:07 Curious ToadCurious Toad 113 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

After researching some more I've given up trying to use the taxonomy template and opted for a plugin to amend the permalinks. I followed some of the advice from this similar question: Taxonomy archive with same slug as custom post type?

Currently I am using an amended archive template for the custom post types and then the WP Better Permalinks plugin to rewrite the permalinks how I need them i.e. example/custom-post-type/custom-taxonomy/post-name/

If you need a simple solution this plugin works very well as far as I can tell. I also used Custom Post Type Permalinks which gives a greater level of control (this works the same way as the default WordPress permalinks settings, in that you can arrange the permalink tags in whichever way you like). The only reason I dropped this plugin is that it refused to work with one out of my five CPTs, even though everything was setup the same.

Hopefully this helps someone else in the future.

Post a comment

comment list (0)

  1. No comments so far