Additional templates for posts and date archives

Theme templates supported by WordPress by default can be limiting in some cases, and while you can always use alternative methods, having named templates is always better solution, since you can separate code the way you want it without conditional if blocks.

In all the lists bellow, red templates are added by GD Custom Posts and Taxonomies Tools Pro plugin.

Custom Post Types Archives

Previous versions on GD CPT Tools Pro already implement archives templates for custom post types. Here is the list:

  • type-{post_type}.php
  • type-{rewrite_slug}.php
  • type.php
  • archive-{post_type}.php
  • archive.php
  • index.php

Single Post and Single Custom Post

GD CPT Tools Pro plugin adds additional post templates based on post ID and on post slug. So, the full list of supported templates is like this:

  • single-{post_type}-{id}.php
  • single-{post_type}-{slug}.php
  • single-{id}.php
  • single-{slug}.php
  • single-{post_type}.php
  • single.php
  • index.php

Date Archives

All types of date archives have only one template by default: date.php. If that one is missing, WP uses archive.php or index.php. GD CPT Tools 2.4 Pro plugin adds several more templates for year, month and day archives:

  • date-year-{year}.php
  • date-{year}.php
  • date-year.php
  • date-month-{monthnum}.php
  • date-month-{year}-{monthnum}.php
  • date-month.php
  • date-{monthnum}.php
  • date-{year}-{monthnum}.php
  • date-day-{year}-{monthnum}-{day}.php
  • date-day-{day}.php
  • date-{year}-{monthnum}-{day}.php
  • date-day.php
  • date.php
  • archive.php
  • index.php

Custom Post Types Date Archives

Similar to date archives above but based on the post type archive. This is added in plugin version 3.5.

  • archive-{post-type}-year-{year}.php
  • archive-{post-type}-{year}.php
  • archive-{post-type}-year.php
  • archive-{post-type}-month-{monthnum}.php
  • archive-{post-type}-month-{year}-{monthnum}.php
  • archive-{post-type}-month.php
  • archive-{post-type}-{monthnum}.php
  • archive-{post-type}-{year}-{monthnum}.php
  • archive-{post-type}-day-{year}-{monthnum}-{day}.php
  • archive-{post-type}-day-{day}.php
  • archive-{post-type}-{year}-{monthnum}-{day}.php
  • archive-{post-type}-day.php
  • archive-{post-type}-date.php
  • archive-{post-type}.php
  • archive.php
  • index.php

Custom Post Types Intersection Archives

Intersections between post types and archives can generate additional rules.

  • intersection-{post-type}-{taxonomy}.php
  • archive-{post-type}-{taxonomy}.php
  • intersection-{post-type}.php
  • intersection.php
  • archive-{post-type}.php
  • taxonomy-{taxonomy}.php
  • taxonomy.php
  • archive.php
  • index.php

First two rules can be expanded with multiple taxonomies, by adding extra taxonomies at the end. If there are 3 taxonomies in intersection it will look like this:

  • intersection-{post-type}-{taxonomy_1}-{taxonomy_2}-{taxonomy_3}.php
  • archive-{post-type}-{taxonomy_1}-{taxonomy_2}-{taxonomy_3}.php

Comments

Leave a Reply