Codex tools: Log in
Languages: English • Français • 日本語 • 한국어 • Русский • Português do Brasil • (Add your language)
Contents |
워드프레스 템플릿은 퍼즐의 조각처럼 결합되어 워드프레스 사이트에서 웹페이지를 표시합니다. 일부 템플릿 (예 : 헤더와 푸터 템플릿 파일)은 모든 웹 페이지에 사용되는 반면 다른 템플릿은 특정 조건 하에서에만 사용됩니다.
이 문서는 다음의 질문에 답해 줄 것입니다.:
특정 유형의 페이지를 볼 때 어떤 서식 파일이 사용되는가?
Since the introduction of Themes in WordPress 1.5, Templates have become more and more configurable. In order to develop WordPress 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.
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 Conditional Tags page and "Query Based" in Theme Development for more information.
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.
If your blog is at http://example.com/blog/ and a visitor clicks on a link to a category page like http://example.com/blog/category/your-cat/: Here is the progression of how WordPress uses the template hierarchy to find and generate the right file.
WordPress looks for a template file in the current Theme's directory that matches the category's ID.
If a visitor goes to your home page at http://example.com/blog/, the following happens:
The following diagram shows which template files are called to generate a WordPress page based on the WordPress Template hierarchy.
A more in depth hierarchy diagram, including template-related conditional tags and body CSS classes, can be found here.
The following sections describe the order in which template files are being called by WordPress for each query type.
(when displaying a single custom post type see the Single Post display section above.)
The WordPress templates system allow you to filter the hierarchy. The filter (located in the get_query_template() function) uses this filter name: "{$type}_template" where $type is the a file name in the hierarchy without the .php extension.
Full list:
For example, let's take the default author hierarchy:
To add author-{role}.php before author.php we can manipulate the actual hierarchy using the 'author_template' hook. This allows a request for /author/username where username has the role of editor to display using author-editor.php if present in the current themes directory.
function author_role_template( $templates='' )
{
$author = get_queried_object();
$role=$author->roles[0];
if(!is_array($templates) && !empty($templates)) {
$templates=locate_template(array("author-$role.php",$templates),false);
}
elseif(empty($templates)) {
$templates=locate_template("author-$role.php",false);
}
else {
$new_template=locate_template(array("author-$role.php"));
if(!empty($new_template)) array_unshift($templates,$new_template);
}
return $templates;
}
add_filter( 'author_template', 'author_role_template' );
wp-includes/theme.php.
wp-includes/template-loader.php.
Template Hierarchy: Category Templates, Tag Templates, Taxonomy Templates, Page Templates, Post Type Templates, Author Templates, Date Templates, Search Templates, 404 Templates, Attachment Templates, Loop Templates