LOST in WP Template Hireachy

The template hierarchy does not provide for archive index pages. This is an issue that was raised through a trac ticket, but that idea was scrapped and will never be implemented due to different theme stuctures across the board

So the following will never exists natively

  • Pages that lists all posts from a given taxonomy

  • Pages that lists posts from all custom post types

  • Pages that displays an index of terms belonging to a taxonomy (same goes for categories, tags and author pages)

The following do exists in the hierarchy

  • Pages that displays all posts from a given term from a custom taxonomy (see taxonomy pages in the template hierarchy)

  • Pages that displays all posts from a given custom post type (see archive pages in the template hierarchy)

With this all said, you can re-evalute your structures. Your terms can be displayed on a taxonomy.php template, taxonomy-{$taxonomy}.php template or taxonomy-{$taxonomy}-{$term}.php template. For this, simply copy your index.php and rename accordingly. To link to the separate term pages, use get_term_link to link to your term pages.

You will need to create a custom page.php template to display all terms under a given taxonomy.

Just for interest sake, I have done a post a while ago about a dynamic page template for custom post types and for categories. How this work, you have only one template respectively. When creating a new page in the backend, you can choose which custom post type or category respectively you need to display on the specific page. So instead of four or five page templates, you will have only one. Either of these two templates can be modified to your liking for taxonomies as well. Here are the two posts

EDIT

From comments

So in my case I am going to have a page called movie-page.php and a taxonomy.php and finally taxonomy-movieTax.php ? right? Just one final question? Do I need to have same structure for archive.php, as well?

Looking at your structure, I would say yes. Just a tip, if you name your page template, call it page-movie.php not the other way around. As I stated in my previous comment

Only if you need a completely different setup for each term, which I don’t think you will do. A single taxonomy.php will work perfectly if you need the same layout for all terms across all four taxonomies. But again, if you need each taxonomy to have a different layout, you can create four different taxonomy-{$taxonomy}.php templates. This is really all up to you and your layout. The hierarchy just simply provides if you need a different layout between taxonomies or terms in a given taxonomy

Archive pages would be different though. Archive pages are used to display your custom post type posts. This archive page will list all posts from your cpt, regardless of taxonomies or terms. You only have one option here apart from the default archive.php, and that is archive-{$post_type}.php

But again, you don’t need to create these custom pages. An archive.php and a taxonomy.php would be more than enough if you do not need any fancy layout differences or very specific needs per custom post type, taxonomy or terms.

Leave a Comment