站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
▼
建站程序
开发
服务器
办公软件
开发教程
▼
服务器教程
软件使用教程
运营教程
热门电子书
▼
CSS教程
WordPress教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
热点词条
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
WordPress:Template Hierarchy
”
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
Seadragon530
(
讨论
|
贡献
)
2008年4月17日 (四) 13:40的版本
(
差异
)
←上一版本
|
最后版本
(
差异
) |
下一版本→
(
差异
)
跳转至:
导航
、
搜索
警告:您正在编辑的是本页面的旧版本。
如果您发布该更改,该版本后的所有更改都会丢失。
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
<div style="border: 1px solid #036; background:#eee; text-align:center; margin:5px; padding:10px">'''注意:''' 本文关于一个高级话题。参见[[WordPress:Stepping Into Templates|走进模板]]作为接触WordPress模板的介绍.</div> == 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. == 介绍 == WordPress模板结合在一起,就象一个难题的各个部分一样,生成了你的WordPress站点上的网页。一些模板(例如页眉和页脚模板文件)可以用在所有的网页上,而另外一写只能在特殊情况下使用。 === What this article is about === This article seeks to answer the following question: <blockquote> ''Which template file(s) will WordPress use when it displays a certain type of page?'' </blockquote> === 本文是关于什么的 === 本文致力于寻找下面问题的答案: <blockquote> ''当WordPress显示特定的页面类型时,会使用哪种模板文件呢?'' </blockquote> === Who might find this useful === Since the introduction of [[WordPress:Using Themes|Themes]] in WordPress v1.5, [[WordPress:Templates]] have become more and more configurable. In order to [[WordPress:Theme_Development|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. === 本文适用对象 === 由于WordPress v1.5 中对[[WordPress:Using Themes|主题]]的介绍,[[WordPress:Templates|模板]]已经越来越可以自由配置使用了。为了[[WordPress:Theme_Development|开发]] WP主题,要正确的理解WordPress选择模板文件在blog上显示多种页面的方式。如果你想要自定义一个已存在的WordPress主题,本文将帮助你确定哪个模板文件需要编辑。 {| cellspacing="3" |- valign="top" |class="MainPageKnowledgeBaseBox" style="border: 1px solid #ffc9c9; padding: 1em; color: #000000; background-color: #fff3f3"| === Conditional Tags and the Template Hierarchy === WordPress provides more than one way to match templates to query types. WordPress Theme developers can also use [[WordPress:Theme_Development#Query-based_Templates|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 [[WordPress:Theme Development#Query-based Templates|Theme Development]] and [[WordPress:Conditional Tags]] pages for more. |} {| cellspacing="3" |- valign="top" |class="MainPageKnowledgeBaseBox" style="border: 1px solid #ffc9c9; padding: 1em; color: #000000; background-color: #fff3f3"| === 条件式标签和模板层次 === WordPress提供了很多方法来配合模板查询类型。WordPress主题开发人员还使用:Theme_Development#Query-based_Templates|条件式标签]]来控制生成一个特定的页面时使用哪个模板。一些WordPress主题可能不能贯彻所有这里说到的模板文件。一些主题Some 使用条件式标签来载入其他的模板文件。参见[[WordPress:Theme Development#Query-based Templates|主题开发]]和[[WordPress:Conditional Tags|条件式标签]] |} == The Template File Hierarchy == === The General Idea === WordPress uses the [[WordPress:Glossary#Query_string|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. == 模板文件层次 == === 概述 === WordPress使用[[WordPress:Glossary#Query_string|字符串查询]] —站点上每个连接包含的信息—来决定使用哪个模板或者模板组合来显示页面。 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. 首先,WordPress把每个字符传查询与类型查询匹配— i.e.决定哪种类型的页面(搜索页面,分类页面,主页等等.)是所需要的。 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主题中哪些模板可用,按照WordPress模板层次的建议排序。 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. WordPress在现用的主题目录中通过特定的名字寻找模板文件,使用下边列在合适的查询结果中的''第一匹配''的模板文件。 With the exception of the basic <tt style="font-weight:bold; color:#036"><nowiki>index.php</nowiki></tt> 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, <tt style="font-weight:bold; color:#036">index.php</tt> (the Theme's home page template file) will be used. 除了基本的<tt style="font-weight:bold; color:#036"><nowiki>index.php</nowiki></tt>模板文件以外,主题开发人员可以选择是否使用某个特定的模板文件。如果WordPress不能使用匹配名字找到相应的模板,它会跳到这个层次中的下一个文件名。如果WordPress不能找到所有的匹配模板文件,<tt style="font-weight:bold; color:#036">index.php</tt>(主题主页模板文件)。 === Examples === If your blog is at <tt style="font-weight:bold; color:#036"><nowiki>http://domain.com/wp/</nowiki></tt> and a visitor clicks on a link to a category page like <tt style="font-weight:bold; color:#036; font-size: 0.8em"><nowiki>http://domain.com/wp/category/your-cat/</nowiki></tt>, 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 <tt style="font-weight:bold; color:#036"><nowiki>category-4.php</nowiki></tt>. If it is missing, WordPress next looks for a generic category template file, <tt style="font-weight:bold; color:#036"><nowiki>category.php</nowiki></tt>. If this file does not exist either, WordPress looks for a generic archive template, <tt style="font-weight:bold; color:#036"><nowiki>archive.php</nowiki></tt>. If it is missing as well, WordPress falls back on the main Theme template file, <tt style="font-weight:bold; color:#036"><nowiki>index.php</nowiki></tt>. === 示例 === 如果你的blog在<tt style="font-weight:bold; color:#036"><nowiki>http://domain.com/wp/</nowiki></tt>,并且访问者点击了一个分类页面连接如<tt style="font-weight:bold; color:#036; font-size: 0.8em"><nowiki>http://domain.com/wp/category/your-cat/</nowiki></tt>,WordPress会在现有的主题目录中寻找匹配的分类ID。如果这个分类ID是4,WordPress会去寻找一个名字为<tt style="font-weight:bold; color:#036"><nowiki>category-4.php</nowiki></tt>的模板文件。如果没有找到,WordPress就会去寻找普通分类模板文件,<tt style="font-weight:bold; color:#036"><nowiki>category.php</nowiki></tt>。如果这个文件也不存在,WordPress就会寻找普通文档模板,<tt style="font-weight:bold; color:#036"><nowiki>archive.php</nowiki></tt>。如果还是没有找到,WordPress就会返回到主页模板文件,<tt style="font-weight:bold; color:#036"><nowiki>index.php</nowiki></tt>. If a visitor goes to your home page at <tt style="font-weight:bold; color:#036"><nowiki>http://domain.com/wp/</nowiki></tt>, WordPress looks for a template file called <tt style="font-weight:bold; color:#036">home.php</tt> and uses it to generate the requested page. If <tt style="font-weight:bold; color:#036">home.php</tt> is missing, WordPress looks for a file called <tt style="font-weight:bold; color:#036">index.php</tt> in the active theme's directory, and uses that template to generate the page. 如果访问者到了你位于<tt style="font-weight:bold; color:#036"><nowiki>http://domain.com/wp/</nowiki></tt>的主页,WordPress就会寻找一个叫做<tt style="font-weight:bold; color:#036">home.php</tt>的模板文件,并且使用它生成请求的页面。如果没有找到<tt style="font-weight:bold; color:#036">home.php</tt>,WordPress就会在主题目录中寻找一个叫做<tt style="font-weight:bold; color:#036">index.php</tt>的文件,使用这个模板来生成页面。 === Visual Overview === The following diagram shows which template files are called to generate a WordPress page based on the WordPress Template hierarchy. It also illustrates the relationship of [[WordPress:Glossary#Query_string|Query Strings]] to corresponding [[WordPress:Conditional Tags]]. === 视觉总览 === 以下代码显示出哪个模板文件被用来生成一个基于WordPress模板层次的WordPress页面了。它还描述了[[WordPress:Glossary#Query_string|字符串查询]]和相应的[[WordPress:Conditional Tags|条件式标签]]的关系 [[WordPress:Image:templatehierarchyexample.png||Graphic Example of the WordPress Template Hierarchy Structure]] <!-- Codex image page: http://codex.wordpress.org/Image:wp_Template_Hierarchy.png --> <small>[http://codex.wordpress.org/images/1/1d/wp_Template_Hierarchy.png Full-Size Image (png)]</small> <small>[http://www.scoutpress.de/download/wp_Template_Hierarchy.zargo Download ArgoUML-0.22-File (zargo)] (external link)</small> [[WordPress:Image:templatehierarchyexample.png|| WordPress模板层次结构图例]] <!-- Codex image page: http://codex.wordpress.org/Image:wp_Template_Hierarchy.png --> <small>[http://codex.wordpress.org/images/1/1d/wp_Template_Hierarchy.png Full-Size Image (png)]</small> <small>[http://www.scoutpress.de/download/wp_Template_Hierarchy.zargo Download ArgoUML-0.22-File (zargo)] (external link)</small> === The Template Hierarchy In Detail === The following sections describe the order in which template files are being called by WordPress for each query type. === 模板层次详解 === 以下部分描述了在模板文件中WordPress调用的每个查询类型的顺序。 === The Main page === :#home.php :#index.php === Single Post page === :#single.php :#index.php === WordPress Page === :#The template selected from the "Page Template" dropdown when editing the [[WordPress:Pages|Page]]. :#[[WordPress:Pages|page.php]] :#index.php <div style="border: 1px solid #ffc9c9; padding: 1em; color: #000000; background-color: #fff3f3">'''Note:''' This section refers to ''WordPress Pages'', not generic posts or web pages from your blog. Please see [[WordPress:Pages|WordPress Pages]] for details. </div> === 主页 === :#home.php :#index.php === 单个文章页面 === :#single.php :#index.php === WordPress 页面 === :#编辑[[WordPress:Pages|页面]]的时候,从"页面模板"下拉菜单中选择模板. :#[[WordPress:Pages|page.php]] :#index.php <div style="border: 1px solid #ffc9c9; padding: 1em; color: #000000; background-color: #fff3f3">'''注意:''' 这里指的是''WordPress 页面'', 不是blog中的一般文章或者网页。参见 [[WordPress:Pages|WordPress 页面]]. </div> === Category page === :#The Category Template with a matching ID. If the category's ID were <tt style="font-weight:bold; color:#036">6</tt>, WordPress would look for [[WordPress:Category Templates|category-6.php]] :#[[WordPress:Category Templates|category.php]] :#[[WordPress:Creating_an_Archive_Index|archive.php]] :#index.php <div style="border: 1px solid #ffc9c9; padding: 1em; color: #000000; background-color: #fff3f3">'''Note:''' See [[WordPress:Category Templates]] for details.</div> === 分类页面 === :#分类模板有一个匹配ID. 如果分类的ID是<tt style="font-weight:bold; color:#036">6</tt>, WordPress 就会寻找[[WordPress:Category Templates|category-6.php]] :#[[WordPress:Category Templates|category.php]] :#[[WordPress:Creating_an_Archive_Index|archive.php]] :#index.php <div style="border: 1px solid #ffc9c9; padding: 1em; color: #000000; background-color: #fff3f3">'''Note:''' See [[WordPress:Category Templates]] for details.</div> === Tag page === :#The Tag Template with a matching slug. If the tag's slug were <tt style="font-weight:bold; color:#036">sometag</tt>, WordPress would look for [[WordPress:Tag Templates|tag-sometag.php]] :#[[WordPress:Tag Templates|tag.php]] :#[[WordPress:Creating_an_Archive_Index|archive.php]] :#index.php <div style="border: 1px solid #ffc9c9; padding: 1em; color: #000000; background-color: #fff3f3">'''Note:''' See [[WordPress:Tag Templates]] for details.</div> === 标签页面 === :#标签模板有一个匹配插槽.如果标签插槽是<tt style="font-weight:bold; color:#036">sometag</tt>, WordPress就会搜索 [[WordPress:Tag Templates|tag-sometag.php]] :#[[WordPress:Tag Templates|tag.php]] :#[[WordPress:Creating_an_Archive_Index|archive.php]] :#index.php <div style="border: 1px solid #ffc9c9; padding: 1em; color: #000000; background-color: #fff3f3">'''Note:''' See [[WordPress:Tag Templates]] for details.</div> === Author page === :#[[WordPress:Author Templates|author.php]] :#[[WordPress:Creating_an_Archive_Index|archive.php]] :#index.php <div style="border: 1px solid #ffc9c9; padding: 1em; color: #000000; background-color: #fff3f3">'''Note:''' The [[WordPress:Author Templates|Author Template]] can be used to display information about authors.</div> === 作者页面 === :#[[WordPress:Author Templates|author.php]] :#[[WordPress:Creating_an_Archive_Index|archive.php]] :#index.php <div style="border: 1px solid #ffc9c9; padding: 1em; color: #000000; background-color: #fff3f3">'''注意:'''[[WordPress:Author Templates|作者模板]] 可以用来显示有关作者的信息.</div> === Date page === For example, a monthly archive page. :#date.php :#[[WordPress:Creating_an_Archive_Index|archive.php]] :#index.php === 日期页面 === 举个例子,一个按月的文档页面。 :#date.php :#[[WordPress:Creating_an_Archive_Index|archive.php]] :#index.php === Search Result page === :#[[WordPress:Creating_a_Search_Page|search.php]] :#index.php === 搜索结果页面 === :#[[WordPress:Creating_a_Search_Page|search.php]] :#index.php === 404 (Not Found) page === :#[[WordPress:Creating_an_Error_404_Page|404.php]] :#index.php <div style="border: 1px solid #ffc9c9; padding: 1em; color: #000000; background-color: #fff3f3">'''Note:''' See [[WordPress:Creating an Error 404 Page]] for more information about the 404 template.</div> === 404 (找不到) 页面 === :#[[WordPress:Creating_an_Error_404_Page|404.php]] :#index.php <div style="border: 1px solid #ffc9c9; padding: 1em; color: #000000; background-color: #fff3f3">'''注意:''' 参见[[WordPress:Creating an Error 404 Page|建立一个错误404页面]]以获得更多有关404页面的信息。</div> === Attachment page === :#attachment.php :#index.php <div style="border: 1px solid #ffc9c9; padding: 1em; color: #000000; background-color: #fff3f3">'''Note:''' See [[WordPress:Using Image and File Attachments#Inserting_Files|Image attachments]] for more information about this template.</div> === 附件页面 === :#attachment.php :#index.php <div style="border: 1px solid #ffc9c9; padding: 1em; color: #000000; background-color: #fff3f3">'''注意:''' 参见[[WordPress:Using Image and File Attachments#Inserting_Files|图片附件]]获得更多有关此模板的信息.</div> == See also == The following links have direct relevance to the topic of this article. [[WordPress:Theme Development]] | [[WordPress:The Loop]] | [[WordPress:Conditional Tags]] | [[WordPress:Template Tags]] | [[WordPress:Using Permalinks]] == 参见 == 以下连接与文章话题直接相关. [[WordPress:Theme Development|主题开发]] | [[WordPress:The Loop|循环]] | [[WordPress:Conditional Tags|条件式标签]] | [[WordPress:Template Tags|模板标签]] | [[WordPress:Using Permalinks|使用Permalinks]]
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)