WIKI使用導(dǎo)航
站長(zhǎng)百科導(dǎo)航
站長(zhǎng)專題
- 網(wǎng)站推廣
- 網(wǎng)站程序
- 網(wǎng)站賺錢
- 虛擬主機(jī)
- cPanel
- 網(wǎng)址導(dǎo)航專題
- 云計(jì)算
- 微博營(yíng)銷
- 虛擬主機(jī)管理系統(tǒng)
- 開(kāi)放平臺(tái)
- WIKI程序與應(yīng)用
- 美國(guó)十大主機(jī)
Theme Development
The following article is about developing or designing your own WordPress Theme. If you wish to learn more about how to install and use Themes, review the documentation regarding WordPress:Using Themes. This topic differs from WordPress:Using Themes because it discusses the technical aspects of writing code to build your own Themes rather than how to activate Themes or where to obtain new Themes.
下面的文章是關(guān)于發(fā)展或者設(shè)計(jì)你自己的WordPress主題。如果你想要學(xué)習(xí)更多的關(guān)于怎樣安裝和使用主題的知識(shí),請(qǐng)查看關(guān)于使用主題的文件。這個(gè)話題與使用主題不同,因?yàn)橹鳈C(jī)發(fā)展探討了編寫代碼來(lái)創(chuàng)建你自己的主題的技術(shù)方法,而不是激活主題,或者在哪兒能得到新的主題。
You may wish to develop WordPress Themes for your own use or for distribution.
Why WordPress Themes[ ]
你可能因?yàn)樽约盒枰褂弥黝},或者因?yàn)榘l(fā)行而發(fā)展新主題。
為什么WordPress 主題[ ]
WordPress Themes are files and styles that work together to create a presentation or look for a WordPress site. Each Theme may be different, offering many choices for users to take advantage of in order to instantly change their website look. Why should you build your own WordPress Theme?
WordPress主題是文件和樣式的結(jié)合體,用來(lái)創(chuàng)建WordPress站點(diǎn)的外觀或者呈現(xiàn)方式。每個(gè)主題可能有所不同,為每個(gè)用戶提供許多選擇,用戶利用這些選擇來(lái)立即地更改它們的站點(diǎn)的外觀。你為什么要?jiǎng)?chuàng)建你自己的WordPress主題?
- To create your own unique WordPress site look
- 創(chuàng)建你自己的獨(dú)特的WordPress站點(diǎn)外觀
- To take advantage of templates, template tags, and the WordPress Loop to generate different web page results and looks.
- 要利用模板, 模板標(biāo)簽, 和 WordPress Loop來(lái)產(chǎn)生不同的網(wǎng)頁(yè)結(jié)果和外觀。
- To provide alternative templates for specific site features, such as category pages and search result pages.
- 為特別的站點(diǎn)功能提供可供選擇的模板,例如類別網(wǎng)頁(yè)和搜索結(jié)果網(wǎng)頁(yè)。
- To quickly switch between two site layouts, or to take advantage of a Theme or style switcher to allow users to change the look of your site.
- 快速地在兩個(gè)站點(diǎn)布局之間進(jìn)行切換,或者利用一個(gè)主題或者樣式切換器,允許用戶改變你的站點(diǎn)的外觀。
- To design WordPress Theme(s) so that others may enjoy your designs through public release.
- 設(shè)計(jì)WordPress主題,公開(kāi)發(fā)行,這樣其他人享用你的設(shè)計(jì)。
A WordPress Theme has many benefits, too. WordPress主題也擁有許多的優(yōu)勢(shì)。
- It separates the presentation styles and template files from the system files so the site will upgrade without drastic changes to the visual presentation of the site.
- 主題將呈現(xiàn)樣式和模板文件從系統(tǒng)文件中分開(kāi),這樣站點(diǎn)更新的時(shí)候,不會(huì)使站點(diǎn)的外觀效果發(fā)生巨大的變化。
- It allows for customization of the presentation and web page results unique to that Theme.
- WordPress主題允許自定義主題獨(dú)特的外觀和網(wǎng)頁(yè)內(nèi)容。
- It allows for quick changes of the look and feel of a WordPress site.
- 能夠快速地改變一個(gè)WordPress站點(diǎn)的外觀和整體效果。
- It takes away the need for a WordPress user to have to learn CSS, HTML, and PHP in order to have a good looking website.
- 不需要WordPress用戶來(lái)學(xué)習(xí)CSS,HTML,和PHP,以創(chuàng)建好的站點(diǎn)外觀。
Why should you build your own WordPress Theme? That's the real question.
你為什么應(yīng)該創(chuàng)建你自己的WordPress主題?這才是真正的問(wèn)題所在。
- It's an opportunity to learn more about CSS, HTML/XHTML, and PHP.
- 這是學(xué)習(xí)更多的關(guān)于CSS,HTML/XHTNL,和PHP知識(shí)的一次機(jī)會(huì)。
- It's an opportunity to put your expertise with CSS, HTML/XHTML, and PHP to work.
- 這是一個(gè)機(jī)會(huì),使你熟練掌握CSS,HTML/XHTML,和PHP。
- It's creative.
- 這具有創(chuàng)造性。
- It's fun (most of the time).
- 這非常地有趣(大多數(shù)時(shí)候)。
- If you release it to the public, you can feel good that you shared and gave something back to the WordPress Community (okay, bragging rights!)
- 如果你將它公開(kāi)發(fā)行,你會(huì)感覺(jué)良好,因?yàn)槟闩cWordPress團(tuán)隊(duì)一起分享你的主題,并且向WordPress 團(tuán)隊(duì) 返回了你的貢獻(xiàn)(好的,bragging rights!)
Anatomy of a Theme[ ]
主題的解析[ ]
WordPress Themes live in subdirectories residing in wp-content/themes/. The Theme's subdirectory holds all of the Theme's style sheet files, template files, an optional functions file (functions.php), and images. For example, a Theme named "test" would probably reside in the directory wp-content/themes/test/.
WordPress主題位于wp-content/themes/的子目錄中。主題的子目錄包含有主題的所有樣式表文件,模板文件,一個(gè)可選擇的的函數(shù)文件(functions.php),和圖像。例如,一個(gè)叫做"測(cè)試"的主題可能會(huì)在wp-content/themes/test/目錄中。
WordPress includes two Themes in the download, a "Classic" and "Default" Theme. The two Themes are different and use different functions and tags to generate their web page results and looks. Examine the files carefully for these Themes to get a better idea of how to build your own Theme files.
WordPress包含有兩個(gè)主題可以下載,一個(gè)是"經(jīng)典的" 一個(gè)是"默認(rèn)的"主題。這兩個(gè)主題是不同的并且使用不同的函數(shù)和標(biāo)簽來(lái)產(chǎn)生各自的網(wǎng)頁(yè)內(nèi)容和外觀。仔細(xì)地檢查這些主題的文件來(lái),以知道怎樣更好地建立你自己的主題文件。
WordPress Themes consist of three main types of files, in addition to images. One is the style sheet called style.css, which controls the presentation (look) of the web pages. The second is the optional functions file (functions.php). The other files are the template files which control the way the web page generates the information from the Database to be displayed as a web page. Let's look at these individually.
WordPress主題除了圖像外,包括三種主要類型的文件。一種是樣式表稱為style.css,這控制了網(wǎng)頁(yè)的外表(外觀)。第二種是可選擇的函數(shù)文件(functions.php)。其它的文件是模板文件,這個(gè)文件控制了數(shù)據(jù)庫(kù)中的信息,在網(wǎng)頁(yè)上的顯示方式。讓我們分別地看看這三種文件。
Theme Style Sheet[ ]
主題樣式表[ ]
In addition to CSS style information for your theme, the stylesheet, style.css must provide details about the Theme in the form of comments. No two Themes are allowed to have the same details listed in their comment headers, as this will lead to problems in the Theme selection dialog. If you make your own Theme by copying an existing one, make sure you change this information first.
除了提供你的主題的CSS樣式信息外,樣式表,style.css 必須提供評(píng)論形式的主題的詳細(xì)信息。評(píng)論標(biāo)題上不能列出兩個(gè)主題同樣的詳細(xì)信息,因?yàn)檫@會(huì)引起主題選擇對(duì)話的錯(cuò)誤。如果你通過(guò)復(fù)制一個(gè)現(xiàn)存的主題來(lái)制作你自己的主題,首先要確定你已經(jīng)更改了這個(gè)信息。
The following is an example of the first few lines of the stylesheet, called the style sheet header, for the Theme "Rose":
下面是主題的"玫瑰"的樣式表前幾行的例子,稱作樣式表標(biāo)題:
/* Theme Name: Rose Theme URI: the-theme's-homepage Description: a-brief-description Author: your-name Author URI: your-URI Template: use-this-to-define-a-parent-theme--optional Version: a-number--optional . <pre>/* 主題名: 玫瑰 主題 URI: 主題的主頁(yè) 描述: 主要的簡(jiǎn)述 作者:你的姓名 作者URI: 你的-URI 模板: 使用-這個(gè)-來(lái)-定義-一個(gè)-母-主題—任意的 版本: 一個(gè)-數(shù)字—隨意的。 General comments/License Statement if any. 如果有許可的話,一般的評(píng)論/許可聲明。 */
- /
The simplest Theme includes only a style.css file, plus images, if any. To create such a Theme, you must specify a set of templates to inherit for use with the Theme by editing the Template: line in the style.css header comments. For example, if you wanted the Theme "Rose" to inherit the templates from another Theme called "test", you would include Template: test in the comments at the beginning of Rose's style.css. Now "test" is the parent Theme for "Rose", which still consists only of a style.css file and the concomitant images, all located in the directory wp-content/themes/Rose. (Note that specifying a parent Theme will inherit all of the template files from that Theme — meaning that any template files in the child Theme's directory will be ignored.)
如果存在最簡(jiǎn)單的主題,這種主題只包括一個(gè)style.css文件和圖像(如果有圖像)。要?jiǎng)?chuàng)建這樣的一個(gè)主題,你必須通過(guò)在style.css標(biāo)題評(píng)論中編輯Template:行,來(lái)規(guī)定一套模板來(lái)繼承使用主題。例如,如果你想要"Rose"主題來(lái)繼承其它的一個(gè)稱作"測(cè)試"的主題的模板,你就會(huì)將評(píng)論中的Template: test放入Rose的tt>style.css開(kāi)端?,F(xiàn)在"test" 是"Rose"的母主題,只包含有一個(gè)style.css文件和一個(gè)相關(guān)的圖像,都在wp-content/themes/Rose目錄中。(注規(guī)定一個(gè)母主題會(huì)從主題&mdash中繼承所有的主題文件;意思是子主題目錄中的任何模板文件都會(huì)被忽視。)
The comment header lines in style.css are required for WordPress to be able to identify a Theme and display it in the Administration Panel under Design > Themes as an available Theme option along with any other installed Themes.
style.css中的評(píng)論標(biāo)題行要求WordPress能夠辨別一個(gè)主題并且將主題顯示在設(shè)計(jì) > 主題下的管理面板與其它安裝好的主題一起,作為可選擇的主題。
Note : When defining the parent Theme, in the Template: section of the comment header, you must use the name of the directory of the style. For example, to use as parent template the Default Wordpress Theme, don't write Template: WordPress Default, but Template: default, because default is the directory of this Theme.
注 : 當(dāng)在評(píng)論標(biāo)題的Template:部分定義一個(gè)母主題的時(shí)候,你必須使用那個(gè)樣式的目錄名。例如,將默認(rèn)的WordPress主題用作母主題,不要寫成模板: WordPress 默認(rèn),要寫成模板: 默認(rèn),因?yàn)槟J(rèn)是這個(gè)主題的目錄。
Functions File[ ]
函數(shù) 文件[ ]
A theme can optionally use a functions file, which resides in the theme subdirectory and is named functions.php. This file basically acts like a plugin, and if it is present in the theme you are using, it is automatically loaded during WordPress initialization (both for admin pages and external pages). Suggested uses for this file:
主題可以隨意地使用函數(shù)文件,這個(gè)文件在主題子目錄中,并且命名為functions.php。文件基本像一個(gè)插件那樣運(yùn)行,而且如果文件呈現(xiàn)在你使用的主題中,會(huì)在WordPress初始化(管理網(wǎng)頁(yè)和外部網(wǎng)頁(yè))的時(shí)候,自動(dòng)載入。建議使用這個(gè)文件:
- Define functions used in several template files of your theme
- Set up an admin screen, giving users options for colors, styles, and other aspects of your theme
- 定義你的主題多個(gè)模板文件中使用的函數(shù)
- 設(shè)置一個(gè)管理界面,提供給用戶顏色,樣式,和你的主題的其它方面的選項(xiàng)
The "Default" WordPress theme contains a functions.php file that defines functions and an admin screen, so you might want to use it as a model. Since functions.php basically functions as a plugin, the WordPress:Function_Reference list is the best place to go for more information on what you can do with this file.
"默認(rèn)"WordPress主題包含一個(gè)functions.php文件,這個(gè)文件定義了函數(shù)和一個(gè)管理界面,這樣你可能想將這個(gè)文件用作一個(gè)模型。因?yàn)?tt>functions.php基本起一個(gè)插件的作用,函數(shù)_參考列表有你怎樣處理這個(gè)文件的更多的信息。
Theme Template Files[ ]
主題模板文件[ ]
Templates are PHP source files used to generate the pages requested by visitors. Let's look at the various templates that can be defined as part of a Theme.
模板是PHP原始文件,根據(jù)訪客要求,用來(lái)產(chǎn)生網(wǎng)頁(yè)的。讓我們來(lái)看看可以被定義為主題部分的不同的模板。
WordPress allows you to define separate templates for the various aspects of your weblog; however, it is not essential to have all these different template files for your blog to function fully. Templates are chosen and generated based upon the WordPress:Template Hierarchy, depending upon what templates are available in a particular Theme. As a Theme developer, you can choose the amount of customization you want to implement using templates. For example, as an extreme case, you can use only one template file, called index.php as the template for all pages generated and displayed by the weblog. A more common use is to have different template files generate different results, to allow maximum customization.
WordPress能夠使你為你的博客的不同部分分別定義模板;然而,使你的博客正常地運(yùn)行,并不一定需要所有的這些不同的模板文件。模板是根據(jù)模板層級(jí)選擇和產(chǎn)生的,取決于特別的主題中擁有什么樣的模板。作為一個(gè)主題開(kāi)發(fā)者,你可以選擇你想使用模板,自定義多少內(nèi)容。例如,一個(gè)極端的例子,你可以為網(wǎng)絡(luò)日志上產(chǎn)生的和顯示的所有的網(wǎng)頁(yè),只使用一個(gè)稱為index.php模板文件,作為模板。一個(gè)更加通常的用法是使用不同的模板文件產(chǎn)生不同的結(jié)果,允許最大化的自定義。
Basic Templates[ ]
基本的模板[ ]
At the very minimum, a WordPress Theme consists of two files:
在最小值的時(shí)候, WordPress主題包含有兩個(gè)文件:
- style.css
- index.php
- style.css
- index.php
Both of these files go into the Theme's directory. The index.php template file is very flexible. It can be used to include all references to the header, sidebar, footer, content, categories, archives, search, error, and other web pages generated by the user on your site. Or it can be subdivided into modular template files, each one taking on part of the workload.
這兩個(gè)文件都?xì)w屬于主題的目錄。index.php 模板文件非常地靈活。它可以被用來(lái)包括關(guān)于標(biāo)題,工具條,頁(yè)腳,內(nèi)容,類別,歸檔,搜索,錯(cuò)誤和你的站點(diǎn)上的用戶創(chuàng)建的其它的網(wǎng)頁(yè)的所有參數(shù)?;蛘咚梢员?i>再次地分到模模板文件,每個(gè)部分都具有一部分的工作量。
If you do not provide any other template files, WordPress will use the built-in default files. For example, if you do not have either a comments.php or comments-popup.php template file, then WordPress will automatically use the wp-comments.php and wp-comments-popup.php template files using WordPress:Template Hierarchy. These default templates may not match your Theme very well, so you probably will want to provide your own. The basic files normally used to subdivide (which go into the Theme's directory) are:
如果你沒(méi)有提供其它任何的模板文件,WordPress會(huì)使用內(nèi)置的默認(rèn)文件。例如,如果你既沒(méi)有comments.php也沒(méi)有comments-popup.php模板文件,WordPress就會(huì)使用模板層級(jí),自動(dòng)地使用wp-comments.php 和wp-comments-popup.php模板文件。這些默認(rèn)模板可能不太匹配你的主題,因此你可能需要提供你自己的模板。用來(lái)再次地切分的基本的文件(歸屬于主題的目錄)是:
- header.php
- sidebar.php
- footer.php
- comments.php
- comments-popup.php
- header.php
- sidebar.php
- footer.php
- comments.php
- comments-popup.php
Using these modular template files, you can put template tags within the index.php master file to include or get these units where you want them to appear in the final generated web page.
使用這些模的模板文件,你可以將這些模板標(biāo)簽放到index.php主要文件中來(lái)包括或者得到這些units,你想讓它們出現(xiàn)在最后產(chǎn)生的網(wǎng)頁(yè)的位置。
- To include the header, use the get_header() template tag.
- 要包含標(biāo)題,請(qǐng)使用get_header()模板標(biāo)簽。
- To include the sidebar, use the get_sidebar() template tag.
- 要包含工具條,使用get_sidebar()模板標(biāo)簽。
- To include the footer, use the get_footer() template tag.
- 要包含頁(yè)腳,使用get_footer() 模板標(biāo)簽。
Here is an example of the include usage:
下面是關(guān)于包含 用法的一個(gè)例子:
<?php get_sidebar(); ?> <?php get_footer(); ?>
<?php get_sidebar(); ?> <?php get_footer(); ?>
For more on how these various Templates work and how to generate different information within them, read the WordPress:Templates documentation.
關(guān)于這些不同模板怎樣運(yùn)行以及怎樣在模板里面產(chǎn)生不同信息的更多內(nèi)容,請(qǐng)閱讀模板文件。
Query-based Templates[ ]
以查詢?yōu)榛A(chǔ)的模板[ ]
WordPress can load different Templates for different query types. There are two ways to do this: as part of the built-in WordPress:Template Hierarchy, and through the use of WordPress:Conditional Tags within WordPress:The Loop of a template file.
WordPress可以為不同的查詢 形式載入不同的模板。有兩種方法可以做到這一點(diǎn):作為內(nèi)置的模板層級(jí)的一部分,通過(guò)在模板文件的Loop中使用條件式標(biāo)簽。
To use the WordPress:Template Hierarchy, you basically need to provide special-purpose Template files, which will automatically be used to override index.php. For instance, if your Theme provides a template called category.php and a category is being queried, category.php will be loaded instead of index.php. If category.php is not present, index.php is used as usual.
要使用模板層級(jí),你只要提供特殊用途的模板文件,這個(gè)文件會(huì)自動(dòng)地覆蓋index.php。例如,如果你的主題提供一個(gè)叫做category.php的模板,并且提供一個(gè)正被查詢的類別,category.php而不是index.php將會(huì)被載入。如果category.php沒(méi)有出現(xiàn),index.php會(huì)照常使用。
You can get even more specific in the Template Hierarchy by providing a file called, for instance, category-6.php -- this file will be used rather than category.php when generating the page for the category whose ID number is 6. (You can find category ID numbers in Manage > Categories if you are logged in as the site administrator in WordPress version 2.3 and below. In WordPress 2.5 the ID column was removed from the Admin panels. You can locate the category id by clicking 'Edit Category' and looking on the URL address bar for the cat_ID value. It will look '...categories.php?action=edit&cat_ID=3' where '3' is the category id). For a more detailed look at how this process works, see WordPress:Category Templates.
通過(guò)提供一個(gè)例如,稱作category-6.php的文件,你可以在模板層級(jí)中得到更加詳細(xì)的信息---當(dāng)為一個(gè)ID號(hào)碼為6的類別產(chǎn)出網(wǎng)頁(yè)的時(shí)候,這個(gè)文件而不是category.php會(huì)被用到。(如果你在WordPress2.3版本以及更低的版本中,以站點(diǎn)管理員的身份登錄,你在 管理 > 類別 下面會(huì)看到這個(gè)類別的ID數(shù)字。在WordPress 2.5版本中,管理面板中移除了ID欄。通過(guò)點(diǎn)擊'編輯類別' ,并且查找URL地址中的cat_ID 參數(shù)值,你可以查找類別id的位置??雌饋?lái)就像'...categories.php?action=edit&cat_ID=3' 其中'3'就是類別 id)。更詳細(xì)地看看這個(gè)過(guò)程是怎樣進(jìn)行的,請(qǐng)看看類別模板。
If your Theme needs to have even more control over which Template files are used than what is provided in the WordPress:Template Hierarchy, you can use WordPress:Conditional Tags. The Conditional Tag basically checks to see if some particular condition is true, within the WordPress Loop, and then you can load a particular template, or put some particular text on the screen, based on that condition.
如果你的主題需要更多地控制使用的哪個(gè)模板文件而不是模板層級(jí)中所提供的內(nèi)容,你可以使用條件式標(biāo)簽。條件式標(biāo)簽基本上是用來(lái)檢查看看在WordPress Loop內(nèi)的,一些特別的條件是否是真的,然后你就可以根據(jù)那個(gè)情況,載入一個(gè)特別的模板,或者在屏面上放一些特別的文本。
For example, to generate a distinctive style sheet in a post only found within a specific category, the code might look like this:
例如,給一個(gè)特別類別中的文章創(chuàng)建一個(gè)樣式表,代碼可能看起來(lái)像這樣的:
<?php if (is_category(9)) { // looking for category 9 posts include(TEMPLATEPATH . '/single2.php'); } else { // put this on every other category post include(TEMPLATEPATH . '/single1.php'); } ?>
<?php if (is_category(9)) { //查找類別9中的文章 包括(TEMPLATEPATH . '/single2.php'); } else { // 每隔一篇文章便放入這個(gè) include(TEMPLATEPATH . '/single1.php'); } ?>
Or, using a query, it might look like this:
或者,使用一個(gè)查詢,這個(gè)查詢可能看起來(lái)像:
<?php $post = $wp_query->post; if ( in_category('9') ) { include(TEMPLATEPATH . '/single2.php'); } else { include(TEMPLATEPATH . '/single1.php'); } ?>
<?php $post = $wp_query->post; if ( in_category('9') ) { include(TEMPLATEPATH . '/single2.php'); } else { include(TEMPLATEPATH . '/single1.php'); } ?>
In either case, this example code will cause different templates to be used depending on the category of the particular post being displayed. Query conditions are not limited to categories, however -- see the WordPress:Conditional Tags article to look at all the options.
在上述任一例子中,代碼會(huì)產(chǎn)生不同的模板,這些模板的使用取決于類別上顯示的文章。查詢條件并不局限于類別,然而—請(qǐng)看看條件式標(biāo)簽文章來(lái)看看所有的選項(xiàng)。
Media Icons[ ]
媒體圖標(biāo)[ ]
This feature is currently broken in WordPress 2.5.
這個(gè)功能當(dāng)前在 WordPress 2.5中破壞了。
Wordpress uses media icons to represent attachment files on your blog and in the Admin interface, if those icons are available.
WordPress使用媒體icons來(lái)代表你的博客和管理界面上的附屬文件,前提是存在這些圖標(biāo)。
It looks for image files named by media type in the images directory of the current theme. (As of Wordpress 2.2, the default theme comes with only one media icon, audio.jpg.)
它要查找當(dāng)前主題的images目錄中的媒體類型所命名的圖像文件。(從Wordpress2.2開(kāi)始,默認(rèn)的主題只有一個(gè)媒體圖標(biāo),audio.jpg。)
For example, for an attachment of MIME type audio/mpeg, Wordpress would look for an icon file at these locations, stopping after the first match (see wp_mime_type_icon):
例如,對(duì)于MIME 類型 audio/mpeg的一個(gè)附屬裝置,WordPress在這些位置中尋找一個(gè)圖標(biāo)文件,在找到第一個(gè)匹配文件后,便停止(請(qǐng)看看wp_mime_type_icon):
- my_theme/images/audio.jpg
- my_theme/images/audio.gif
- my_theme/images/audio.png
- my_theme/images/mpeg.jpg
- my_theme/images/mpeg.gif
- my_theme/images/mpeg.png
- my_theme/images/audio_mpeg.jpg
- my_theme/images/audio_mpeg.gif
- my_theme/images/audio_mpeg.png
- my_theme/images/audio.jpg
- my_theme/images/audio.gif
- my_theme/images/audio.png
- my_theme/images/mpeg.jpg
- my_theme/images/mpeg.gif
- my_theme/images/mpeg.png
- my_theme/images/audio_mpeg.jpg
- my_theme/images/audio_mpeg.gif
- my_theme/images/audio_mpeg.png
Theme Template Files List[ ]
主題模板文件列表[ ]
Here is the list of Theme template files recognized by WordPress. Of course, your Theme can contain any other style sheets, images, or files. Just keep in mind that the following have special meaning to WordPress -- see WordPress:Template Hierarchy for more information.
下面是WordPress 識(shí)別的主題模板文件的列表。當(dāng)然,你的主題可以包含任何其它的樣式表,圖像,或者文件。只要牢記下面的內(nèi)容對(duì)于WordPress具有一些特別的意義—更多的信息請(qǐng)看看模板層級(jí)。
- style.css
- The main stylesheet. This must be included with your Theme, and it must contain the information header for your Theme.
- style.css
- 主要的樣式表。這個(gè)必須包含在你的主題中,而且必須包含你的主題的信息標(biāo)題。
- index.php
- The main template. If your Theme provides its own templates, index.php must be present.
- index.php
- 主要的模板。如果你的主題提供自己的模板,index.php必須呈現(xiàn)。
- comments.php
- The comments template. If not present, comments.php from the "default" Theme is used.
- comments.php
- 評(píng)論模板。如果沒(méi)有出現(xiàn),來(lái)自"默認(rèn)"主題的comments.php就會(huì)被使用。
- comments-popup.php
- The popup comments template. If not present, comments-popup.php from the "default" Theme is used.
- comments-popup.php
- 彈出的評(píng)論模板。如果沒(méi)有出現(xiàn),來(lái)自"默認(rèn)"主題的comments-popup.php就被使用。
- home.php
- The home page template.
- home.php
- 主頁(yè)模板。
- single.php
- The single post template. Used when a single post is queried. For this and all other query templates, index.php is used if the query template is not present.
- single.php
- 單一的文章模板。當(dāng)一篇單一的文章被查詢的時(shí)候,便會(huì)用到這個(gè)模板。對(duì)于這個(gè)和其它的查詢模板,如果查詢模板沒(méi)有出現(xiàn),就會(huì)用到index.php。
- page.php
- The page template. Used when an individual Page is queried.
- page.php
- 網(wǎng)頁(yè)模板。當(dāng)一個(gè)單獨(dú)的網(wǎng)頁(yè)得到查詢的時(shí)候,便會(huì)用到這個(gè)。
- category.php
- The category template. Used when a category is queried.
- category.php
- The 類別模板。當(dāng)詢問(wèn)類別的時(shí)候,便會(huì)用到這個(gè)。
- author.php
- The author template. Used when an author is queried.
- author.php
- 作者模板。查詢作者的時(shí)候,會(huì)使用到這個(gè)。
- date.php
- The date/time template. Used when a date or time is queried. Year, month, day, hour, minute, second.
- date.php
- 日期/時(shí)間模板。當(dāng)查詢?nèi)掌诨蛘邥r(shí)間的時(shí)候,便會(huì)用到這個(gè)模板。年,月,日,時(shí),分,秒。
- archive.php
- The archive template. Used when a category, author, or date is queried. Note that this template will be overridden by category.php, author.php, and date.php for their respective query types.
- archive.php
- 歸檔模板。當(dāng)查詢一個(gè)類別,作者或者日期的時(shí)候,便會(huì)用到這個(gè)模板。注意這個(gè)模板會(huì)被category.php, author.php, 和date.php各自的查詢形式覆蓋。
- search.php
- The search results template. Used when a search is performed.
- 404.php
- The 404 Not Found template. Used when WordPress cannot find a post or page that matches the query.
- search.php
- 搜索結(jié)果模板。當(dāng)執(zhí)行一個(gè)搜索的時(shí)候,便會(huì)用到這個(gè)模板。
- 404.php
- 404 沒(méi)有找到模板。當(dāng)WordPress找不到匹配查詢的文章或者網(wǎng)頁(yè)的時(shí)候,便會(huì)用到這個(gè)模板。
These files have a special meaning with regard to WordPress because they are used as a replacement for index.php, when available, according to the WordPress:Template Hierarchy, and when the corresponding Conditional Tag (a.k.a is_*(); function) returns true. For example, if only a single post is being displayed, the is_single() function returns 'true', and, if there is a single.php file in the active Theme, that template is used to generate the page.
這些文件有關(guān)于WordPress的特別意思因?yàn)檫@些文件用來(lái)作為index.php替代品,條件是這些文件存在,根據(jù)模板層級(jí),而且相應(yīng)的條件式標(biāo)簽 (a.k.a is_*(); 函數(shù)) 返回是真。例如,如果只顯示一篇文章,is_single()函數(shù)返回'真的',如果歸檔主題中有single.php文件,這個(gè)模板就用來(lái)創(chuàng)建網(wǎng)頁(yè)。
Referencing Files From a Template[ ]
參考模板中的文件[ ]
The WordPress Default Theme (based on Michael Heilemann's Kubrick layout for WordPress 1.2) provides a good example of how queries are mapped onto templates.
WordPress默認(rèn)主題(以Michael Heilemann的KubrickWordPress1.2布局為基礎(chǔ))提供了一個(gè)非常好的例子,關(guān)于查詢是怎樣映射進(jìn)模板的。
The code <?php bloginfo('template_directory'); ?> inserts the URL of the template directory into the template output. You can append any additional URI information to this output to reference files in your Theme.
代碼<?php bloginfo('template_directory'); ?>將模板目錄的URL嵌入了模板輸出中。你可以將任何額外的URI信息添加到你的主題的參考文件的這個(gè)輸出中。
The code <?php bloginfo('stylesheet_directory'); ?> inserts the URL of the directory that contains the current Theme stylesheet into the template output. You can append any additional URI information to this output to reference files for your Theme, specifically those that are used by the stylesheet.
代碼<?php bloginfo('stylesheet_directory'); ?>嵌入了目錄的URI,這個(gè)URI將當(dāng)前的主題樣式表包含到模板輸出中。你可以添加任何額外的URI到你的主題的參考文件的輸出中,特別是樣式表使用的那些。
The constant TEMPLATEPATH is a reference to the absolute path to the template directory for the current Theme (without the / at the end).
恒量TEMPLATEPATH是當(dāng)前主題模板目錄絕對(duì)路徑的一個(gè)參考(后面沒(méi)有/)。
Note that URIs that are used in the stylesheet are relative to the stylesheet, not the page that references the stylesheet. This obviates the need to include PHP code in the CSS file to specify directories. For example, if you include an images/ directory in your Theme, you need only specify this relative directory in the CSS, like so:
注意用在樣式表中的URIs與樣式表相關(guān),但是與指代樣式表的網(wǎng)頁(yè)并不相關(guān)。這就避免了在CSS文件中包含PHP代碼來(lái)規(guī)定類別。例如,如果你的主題包含了一個(gè)images/目錄,你只需要在CSS中規(guī)定這個(gè)相關(guān)的目錄,像這樣的:
h1 { background-image: URL(images/my_background.jpg); }
h1 { background-image: URL(images/my_background.jpg); }
It is a good practice to use URIs in the manner described above to reference files from within a template, since, then your template will not depend on absolute paths.
對(duì)于模板中的參考文件以以上的方式使用URIs是一個(gè)好的做法,因?yàn)?,這樣你的模板就不會(huì)依賴于絕對(duì)路徑了。
Defining Custom Templates[ ]
定義自定義模板[ ]
It is possible to use the WordPress plugin system to define additional templates that are shown based on your own custom criteria. This advanced feature can be accomplished using the template_redirect action hook. More information about creating plugins can be found in the WordPress:Plugin API reference.
可以使用WordPress插件系統(tǒng)來(lái)定義額外的模板,這種模板以你自己自定義的標(biāo)準(zhǔn),顯示。這個(gè)高級(jí)的功能通過(guò)使用template_redirect action hook可以得到實(shí)現(xiàn)。更多的關(guān)于創(chuàng)建插件的信息可以在插件API參考中找到。
Plugin API Hooks[ ]
插件API Hooks[ ]
When developing Themes, it's good to keep in mind that your Theme should be set up so that it can work well with any WordPress plugins you (or another Theme user) might decide to install. Plugins add functionality to WordPress via "Action Hooks" (see WordPress:Plugin API for more information). Most Action Hooks are within the core PHP code of WordPress, so your Theme does not have to have any special tags for them to work. But a few Action Hooks do need to be present in your Theme, in order for Plugins to display information directly in your header, footer, sidebar, or in the page body. Here is a list of the special Action Hook Template Tags you need to include:
發(fā)展主題的時(shí)候,最好牢記你的主題得到了設(shè)置,這樣它就能夠很好地配合你(或者其它的主題用戶)可能決定安裝的WordPress插件。插件通過(guò)"Action Hooks"來(lái)給WordPress添加功能(請(qǐng)看看插件API得到更多的信息)。大多數(shù)Action Hooks是在WordPress核心PHP代碼內(nèi)部,因此你的主題不要為它們的運(yùn)行準(zhǔn)備任何特別標(biāo)簽。但是有幾個(gè)Action Hooks的確需要呈現(xiàn)在你的主題上,為了使插件能夠直接地在你的頁(yè)眉,頁(yè)腳,工具條,或者在網(wǎng)頁(yè)上顯示信息。下面是你需要的特別Action Hook模板標(biāo)簽列表:
- wp_head
- wp_head
- Goes in the HTML <head> element of a theme; header.php template. Example plugin use: add javascript code.
- 進(jìn)入 HTML <head> 主題元素; header.php 模板。例子插件使用: 添加 javascript 代碼。
- Usage: <?php do_action('wp_head'); ?>
- -or- <?php wp_head(); ?>
- 用法: <?php do_action('wp_head'); ?>
- -or- <?php wp_head(); ?>
- wp_footer
- wp_footer
- Goes in the "footer" of a theme; footer.php template. Example plugin use: insert PHP code that needs to run after everything else, at the bottom of the footer.
- 進(jìn)入主題的"頁(yè)腳"中; footer.php 模板。例子插件使用: 在頁(yè)腳的底部,嵌入需要在所有內(nèi)容運(yùn)行之后運(yùn)行的PHP代碼。
- Usage: <?php do_action('wp_footer'); ?>
- -or- <?php wp_footer(); ?>
- 用法: <?php do_action('wp_footer'); ?>
- -or- <?php wp_footer(); ?>
- wp_meta
- wp_meta
- Typically goes in the <li>Meta</li> section of a theme's menu or sidebar; sidebar.php template. Example plugin use: include a rotating advertisement or a tag cloud.
- 通常進(jìn)入主題的菜單或者工具條的<li>Meta</li>部分; sidebar.php 模板。 例子插件使用: 包括旋轉(zhuǎn)的廣告或者標(biāo)簽cloud。
- Usage: <?php do_action('wp_meta'); ?>
- -or- <?php wp_meta(); ?>
- 用法: <?php do_action('wp_meta'); ?>
- -or- <?php wp_meta(); ?>
- comment_form
- comment_form
- Goes in comments.php and comments-popup.php, directly before the comment form's closing tag (
</form>
). Example plugin use: display a comment preview.
- 進(jìn)入 comments.php 和comments-popup.php中, 直接在評(píng)論形式的關(guān)閉標(biāo)簽 (
</form>
)前面。 例子插件使用: 顯示一個(gè)評(píng)論預(yù)覽。
- Usage: <?php do_action('comment_form', $post->ID); ?>
- 用法: <?php do_action('comment_form', $post->ID); ?>
For a real world usage example, you'll find these plugin hooks included in the default theme's templates.
對(duì)于真實(shí)的世界用法的例子,你將會(huì)發(fā)現(xiàn)這些插件hooks包含在默認(rèn)主題的模板中。
Theme Development General Guidelines[ ]
主題發(fā)展一般指導(dǎo)方針[ ]
Please be clear about the following in your documentation (a README file included with your Theme helps many users over any potential stumbling blocks):
請(qǐng)了解你的文件中的以下內(nèi)容(一個(gè)包含在你的主題中的README文件幫助許多用戶克服了許多潛在的問(wèn)題):
- Indicate precisely what your Theme and template files will achieve.
- 明確地指出你的主題和模板文件要獲得什么。
- Indicate deficiencies in your Themes, if any.
- 如果你的主題有什么缺陷的話,將它指出來(lái)。
- Clearly reference any special modifications in comments within the template and style sheet files. Add comments to modifications, template sections, and CSS styles, especially those which cross template files.
- 明確地指出模板和樣式表文件中評(píng)論任何特別的修改。給更改,模板部分,CSS樣式,特別是那些穿過(guò)模板文件的CSS樣式添加評(píng)論。
- If you have any special requirements, which may include custom RewriteRules, or the use of some additional, special templates, images or files, please explicitly state the steps of action a user should take to get your Theme working.
- 如果你有什么特別的要求,這些要求可能包括自定義RewriteRules,或者使用一些額外的,特別的模板,圖像或者文件,請(qǐng)清楚地描述用戶應(yīng)該采取那些措施,以使你的主題運(yùn)行。
- Try and test your Theme across browsers to catch at least a few of the problems the users of the Theme may find later.
- 試著測(cè)試你的主題跨越瀏覽器至少發(fā)現(xiàn)幾個(gè),未來(lái)主題用戶可能碰到的問(wèn)題。
- Provide contact information (web page or email), if possible, for support information and questions.
- 如果可能的話,提供聯(lián)系信息(網(wǎng)頁(yè)或者電子郵件),來(lái)支持信息和問(wèn)題。
Take time to read through WordPress:Designing Themes for Public Release, an article with good tips on preparing your Theme for the public.
花一些時(shí)間來(lái)通讀為了公共發(fā)行而設(shè)計(jì)主題,這篇文章有許多關(guān)于怎樣準(zhǔn)備你的主題來(lái)公共發(fā)行的好的貼士。
References and Resources[ ]
參考和資源[ ]
There is a comprehensive list of WordPress Theme and Template File resources in the WordPress:Templates article.
在模板文章中有WordPress主題和模板文件資源。