• 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細

このWikiはいつでも誰でも編集できます

トーク:テンプレート階層

提供: WordPress Codex 日本語版
2008年3月9日 (日) 17:29時点におけるBono (トーク | 投稿記録)による版 (新しいページ: '== 英語版と変えている部分について == * 一通り和訳したものの、意図が不明瞭な部分や過剰装飾に思える箇所がある。[http://codex.wo...')

(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

英語版と変えている部分について

  • 一通り和訳したものの、意図が不明瞭な部分や過剰装飾に思える箇所がある。2007年4月15日の編集で大きく変化している。
  • en:Creating an Archive Indexarchives.php(デフォルトテーマの「ページテンプレート」)についてのページなので、archive.php に付いているリンクを外す。本家版ではリンクの付け外しが繰り返されているので、ノートで話し合いたいが、英語で提案できない。。orz
  • 例示の domain.com は実在するので example.com に訂正(下表でも)。


最新版 4月編集前

Introduction

WordPress Templates fit together like the pieces of a puzzle to generate the web pages on your WordPress site. Some templates (the header and footer template files for example) are used on all the web pages, while others are used only under specific conditions.

What this article is about

This article seeks to answer the following question:

Which template file(s) will WordPress use when it displays a certain type of page?

Who might find this useful

Since the introduction of Themes in WordPress v1.5, Templates have become more and more configurable. In order to develop WP themes, a proper understanding of the way WordPress selects template files to display the various pages on your blog is essential. If you seek to customize an existing WordPress theme, this article aims to help you decide which template file needs editing.

Conditional Tags and the Template Hierarchy

WordPress provides more than one way to match templates to query types. WordPress Theme developers can also use Conditional Tags to control which templates will be used to generate a certain page. Some WordPress Themes may not implement all of the template files described here. Some Themes use conditional tags to load other template files. See the Theme Development and Conditional Tags pages for more.

The Template File Hierarchy

The General Idea

WordPress uses the Query String — information contained within each link on your web site — to decide which template or set of templates will be used to display the page.

First, WordPress matches every Query String to query types — i.e. it decides what type of page (a search page, a category page, the home page etc.) is being requested.

Templates are then chosen — and web page content is generated — in the order suggested by the WordPress Template hierarchy, depending upon what templates are available in a particular WordPress Theme.

WordPress looks for template files with specific names in the current Theme's directory and uses the first matching template file listed under the appropriate query section below.

With the exception of the basic index.php template file, Theme developers can choose whether they want to implement a particular template file or not. If WordPress cannot find a template file with a matching name, it skips down to the next file name in the hierarchy. If WordPress cannot find any matching template file, index.php (the Theme's home page template file) will be used.

Examples

If your blog is at http://example.com/wp/ and a visitor clicks on a link to a category page like http://example.com/wp/category/your-cat/, WordPress looks for a template file in the current Theme's directory that matches the category's ID. If the category's ID is 4, WordPress looks for a template file named category-4.php. If it is missing, WordPress next looks for a generic category template file, category.php. If this file does not exist either, WordPress looks for a generic archive template, archive.php. If it is missing as well, WordPress falls back on the main Theme template file, index.php.

If a visitor goes to your home page at http://example.com/wp/, 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.

Visual Overview

(省略)

The Template Hierarchy In Detail

The following sections describe the order in which template files are being called by WordPress for each query type.

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

(省略)

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.

(以下、階層リスト) (以下、階層リスト)