Template Hierarchy

From 워드프레스(WORDPRESS) 한국어 위키

Jump to: navigation, search

Contents

Introduction

Templates are what WordPress uses to format your WordPress site. Since the introduction of Themes in WordPress v1.5, Templates have become more and more configurable. You can develop new themes with a great amount of customization. If template files are new to you, see Stepping Into Templates. In order to develop or customize themes, a proper understanding of the way WordPress selects template files for displaying the various pages on your blog is essential.

This document attempts to answer the following question.

What template file will WordPress use when the _______________ (page) is displayed?

Visual Overview

This diagram shows which template-files are called in which hierarchy depending on the url the visitor requests. There are also the Conditional Tags (grey text) for each request/page.

wp_Template_Hierarchy.png

Download Image (PNG)

Download ArgoUML-0.22-File (zargo)

The Template Selection Hierarchy

In the sections that follow, the section heading fills in the blank in the question above. WordPress looks in the current theme's directory and uses the first template file it finds from the list under the appropriate section below. Note the parallels between the Template Hierarchy and the Conditional Tags.

For example, if your blog is at http://example.com/wordpress/ and a visitor loads the page http://example.com/wordpress/, WordPress looks for a template file called home.php and uses it to generate the requested page. If home.php is missing, WordPress looks for a file called index.php in the active theme's directory, and uses that template to generate the page.

The Main page

  1. home.php
  2. index.php

Single Post page

  1. single.php
  2. index.php

PAGE page

This section refers to WordPress Pages, not any generic webpage from your blog. Please see Pages for more detailed information.

  1. The template selected from the "Page Template" dropdown when editing the Page.
  2. page.php
  3. index.php

Category page

You can customize Category Templates. In this example, the category in question has a category identification number (cat id) of 6.

  1. category-6.php
  2. category.php
  3. archive.php
  4. index.php

Please see Category Templates for more information.

Author page

The Author Templates present information on post authors.

  1. author.php
  2. archive.php
  3. index.php

Date page

For example, a monthly archive page.

  1. date.php
  2. archive.php
  3. index.php

Search Result page

  1. search.php
  2. index.php

404 Not Found page

  1. 404.php
  2. index.php
Personal tools