WordPress Hierarchy and Files

Articles

Post Template Files

  • home.php
  • single.php – For viewing a single post. Most times creating single-post.php is not necessary.
    • single-{post-type}.php – Used to set a custom type’s template.
      • e.g., if there is a custom type of book: single-book.php
  • archive.php – Usually there is not a need to create separate author.php and date.php templates.
    • author.php
    • date.php
    • archive-{post-type}.php – Used to set a custom type’s archive template.
  • category.php
  • tag.php
  • taxonomy.php
  • search.php
  • index.php – Catch-all if a more specific template is not available

Page Template Files

  • Apply only to pages, not to posts or custom post types, etc.
  • Any page template you give a name can be utilized by a WordPress user via Pages–> Add New –> Attributes –> Template.
  • You can use a prefix on templates, e.g. page_two-columns.php, but don’t use page-two-columns.php, this holds special meaning in WP.
  • Make a copy of existing page.php file with a different name, this can be the base for a new template.
  • To give a template a name, at top:
    <?php /* Template Name: Example Template */ ?>
  • page-{slug}.php – example: page-about.php.
  • page-{id}.php
  • page.php
  • $custom.php
  • front-page.php

Attachment Template Files

  • MIME_type.php
  • attachment.php – View single file attachment.
  • single-attachment.php
  • image.php – More specific version of attachment, used when viewing single image.

Custom Post Type Template Files

  • single-{post-type}.php
  • archive-{post-type}.php

Partial and Miscellaneous Template Files

  • 404.php
  • author.php – Page for an individual author.
  • comments.php
  • date.php – Show posts by date/time.
  • header.php
  • footer.php
  • search.php – Search results.
  • sidebar.php
  • content-{$slug}.php
  • style.css – Main stylesheet.
  • rtl.css – Right-to-left languages stylesheet.
  • front-page.php – Used for blog post index or static page.
  • home.php – Used for the front page if a static page is not set.
    • Is always used as the blog posts index page, even if static page set.

Taxonomy Templates

  • taxonomy-{taxonomy}-{term}.php
  • taxonomy-{taxonomy}.php
  • taxonomy.php – For terms in custom taxonomies.
    • Custom: taxonomy-{taxonomy}-{term],php
    • Post Formats: taxonomy-post_format-post-format-link.php
  • tag-{slug}.php
  • tag-{id}.php
  • tag.php – When visitors want to see posts organized by tags.
  • category-{slug}.php
  • category-{ID}.php
%d bloggers like this: