久久精品水蜜桃av综合天堂,久久精品丝袜高跟鞋,精品国产肉丝袜久久,国产一区二区三区色噜噜,黑人video粗暴亚裔
站長百科 | 數(shù)字化技能提升教程 數(shù)字化時代生存寶典
首頁
數(shù)字化百科
電子書
建站程序
開發(fā)
服務(wù)器
辦公軟件
開發(fā)教程
服務(wù)器教程
軟件使用教程
運營教程
熱門電子書
WordPress教程
寶塔面板教程
CSS教程
Shopify教程
導航
程序頻道
推廣頻道
網(wǎng)賺頻道
人物頻道
網(wǎng)站程序
網(wǎng)頁制作
云計算
服務(wù)器
CMS
論壇
網(wǎng)店
虛擬主機
cPanel
網(wǎng)址導航
WIKI使用導航
WIKI首頁
最新資訊
網(wǎng)站程序
站長人物
頁面分類
使用幫助
編輯測試
創(chuàng)建條目
網(wǎng)站地圖
站長百科導航
站長百科
主機偵探
IDCtalk云說
跨境電商導航
WordPress啦
站長專題
網(wǎng)站推廣
網(wǎng)站程序
網(wǎng)站賺錢
虛擬主機
cPanel
網(wǎng)址導航專題
云計算
微博營銷
虛擬主機管理系統(tǒng)
開放平臺
WIKI程序與應(yīng)用
美國十大主機
編輯“
Theme Development
”
人物百科
|
營銷百科
|
網(wǎng)賺百科
|
站長工具
|
網(wǎng)站程序
|
域名主機
|
互聯(lián)網(wǎng)公司
|
分類索引
跳轉(zhuǎn)至:
導航
、?
搜索
警告:
您沒有登錄。如果您做出任意編輯,您的IP地址將會公開可見。如果您
登錄
或
創(chuàng)建
一個賬戶,您的編輯將歸屬于您的用戶名,且將享受其他好處。
反垃圾檢查。
不要
加入這個!
__TOC__ __TOC__ 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è)計你自己的WordPress主題。如果你想要學習更多的關(guān)于怎樣安裝和使用主題的知識,請查看關(guān)于[[WordPress:Using Themes|使用主題]]的文件。這個話題與[[WordPress:Using Themes|使用主題]]不同,因為主機發(fā)展探討了編寫代碼來創(chuàng)建你自己的主題的技術(shù)方法,而不是激活主題,或者在哪兒能得到新的主題。 You may wish to develop WordPress Themes for your own use or [[WordPress:Designing Themes for Public Release|for distribution]]. ==Why WordPress Themes== 你可能因為自己需要使用主題,或者[[WordPress:Designing Themes for Public Release|因為發(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é)合體,用來創(chuàng)建WordPress站點的外觀或者呈現(xiàn)方式。每個主題可能有所不同,為每個用戶提供許多選擇,用戶利用這些選擇來立即地更改它們的站點的外觀。你為什么要創(chuàng)建你自己的WordPress主題? * To create your own unique WordPress site look *創(chuàng)建你自己的獨特的WordPress站點外觀 * To take advantage of [[WordPress:Stepping Into Templates|templates]], [[WordPress:Template Tags|template tags]], and [[WordPress:The Loop in Action|the WordPress Loop]] to generate different web page results and looks. *要利用[[WordPress:Stepping Into Templates|模板]], [[WordPress:Template Tags|模板標簽]], 和 [[WordPress:The Loop in Action| WordPress Loop]]來產(chǎn)生不同的網(wǎng)頁結(jié)果和外觀。 * To provide alternative templates for specific site features, such as [[WordPress:Category Templates|category pages]] and search result pages. *為特別的站點功能提供可供選擇的模板,例如[[WordPress:Category Templates|類別網(wǎng)頁]]和搜索結(jié)果網(wǎng)頁。 * To quickly switch between two site layouts, or to take advantage of a [[WordPress:Plugins|Theme or style switcher]] to allow users to change the look of your site. *快速地在兩個站點布局之間進行切換,或者利用一個[[WordPress:Plugins|主題或者樣式切換器]],允許用戶改變你的站點的外觀。 * To design WordPress Theme(s) so that others may enjoy your designs through public release. *設(shè)計WordPress主題,公開發(fā)行,這樣其他人享用你的設(shè)計。 A WordPress Theme has many benefits, too. WordPress主題也擁有許多的優(yōu)勢。 * It separates the presentation styles and [[WordPress:Stepping Into Templates|template files]] from the system files so the site will upgrade without drastic changes to the visual presentation of the site. *主題將呈現(xiàn)樣式和[[WordPress:Stepping Into Templates|模板文件]]從系統(tǒng)文件中分開,這樣站點更新的時候,不會使站點的外觀效果發(fā)生巨大的變化。 * It allows for customization of the presentation and web page results unique to that Theme. *WordPress主題允許自定義主題獨特的外觀和網(wǎng)頁內(nèi)容。 * It allows for quick changes of the look and feel of a WordPress site. *能夠快速地改變一個WordPress站點的外觀和整體效果。 * 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用戶來學習CSS,HTML,和PHP,以創(chuàng)建好的站點外觀。 Why should you build your own WordPress Theme? That's the real question. 你為什么應(yīng)該創(chuàng)建你自己的WordPress主題?這才是真正的問題所在。 * It's an opportunity to learn more about CSS, HTML/XHTML, and PHP. *這是學習更多的關(guān)于CSS,HTML/XHTNL,和PHP知識的一次機會。 * It's an opportunity to put your expertise with CSS, HTML/XHTML, and PHP to work. *這是一個機會,使你熟練掌握CSS,HTML/XHTML,和PHP。 * It's creative. *這具有創(chuàng)造性。 * It's fun (most of the time). *這非常地有趣(大多數(shù)時候)。 * If you [[WordPress:Designing Themes for Public_Release|release it to the public]], you can feel good that you shared and gave something back to the [[WordPress:Contributing_to_WordPress|WordPress Community]] (okay, bragging rights!) *如果你[[WordPress:Designing Themes for Public_Release|將它公開發(fā)行]],你會感覺良好,因為你與WordPress團隊一起分享你的主題,并且向[[WordPress:Contributing_to_WordPress|WordPress 團隊]] 返回了你的貢獻(好的,bragging rights!) ==Anatomy of a Theme== ==主題的解析== WordPress Themes live in subdirectories residing in <tt>wp-content/themes/</tt>. The Theme's subdirectory holds all of the Theme's style sheet files, [[WordPress:Stepping Into Templates|template files]], an optional functions file (<tt>functions.php</tt>), and images. For example, a Theme named "test" would probably reside in the directory <tt>wp-content/themes/test/</tt>. WordPress主題位于<tt>wp-content/themes/</tt>的子目錄中。主題的子目錄包含有主題的所有樣式表文件,[[WordPress:Stepping Into Templates|模板文件]],一個可選擇的的函數(shù)文件(<tt>functions.php</tt>),和圖像。例如,一個叫做"測試"的主題可能會在<tt>wp-content/themes/test/</tt>目錄中。 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包含有兩個主題可以下載,一個是"經(jīng)典的" 一個是"默認的"主題。這兩個主題是不同的并且使用不同的函數(shù)和標簽來產(chǎn)生各自的網(wǎng)頁內(nèi)容和外觀。仔細地檢查這些主題的文件來,以知道怎樣更好地建立你自己的主題文件。 WordPress Themes consist of three main types of files, in addition to images. One is the style sheet called <tt>style.css</tt>, which controls the presentation (look) of the web pages. The second is the optional functions file (<tt>functions.php</tt>). The other files are the [[WordPress:Stepping Into Templates|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主題除了圖像外,包括三種主要類型的文件。一種是樣式表稱為<tt>style.css</tt>,這控制了網(wǎng)頁的外表(外觀)。第二種是可選擇的函數(shù)文件(<tt>functions.php</tt>)。其它的文件是[[WordPress:Stepping Into Templates|模板文件]],這個文件控制了數(shù)據(jù)庫中的信息,在網(wǎng)頁上的顯示方式。讓我們分別地看看這三種文件。 ===Theme Style Sheet=== ===主題樣式表=== In addition to CSS style information for your theme, the stylesheet, <tt>style.css</tt> '''''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 [[WordPress:Administration_Panels#Design_-_Change_the_Look_of_your_Blog|Theme selection dialog]]. If you make your own Theme by copying an existing one, make sure you change this information first. 除了提供你的主題的CSS樣式信息外,樣式表,<tt>style.css</tt> '''''必須'''''提供評論形式的主題的詳細信息。評論標題上不能列出'''''兩個主題同樣的詳細信息''''',因為這會引起[[WordPress:Administration_Panels#Design_-_Change_the_Look_of_your_Blog|主題選擇對話]]的錯誤。如果你通過復制一個現(xiàn)存的主題來制作你自己的主題,首先要確定你已經(jīng)更改了這個信息。 The following is an example of the first few lines of the stylesheet, called the style sheet header, for the Theme "Rose": 下面是主題的"玫瑰"的樣式表前幾行的例子,稱作樣式表標題: <pre>/* 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: 主題的主頁 描述: 主要的簡述 作者:你的姓名 作者URI: 你的-URI 模板: 使用-這個-來-定義-一個-母-主題—任意的 版本: 一個-數(shù)字—隨意的。 General comments/License Statement if any. 如果有許可的話,一般的評論/許可聲明。 */</pre> */</pre> The simplest Theme includes only a <tt>style.css</tt> 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 <tt>Template:</tt> line in the <tt>style.css</tt> header comments. For example, if you wanted the Theme "Rose" to inherit the templates from another Theme called "test", you would include <tt>Template: test</tt> in the comments at the beginning of Rose's <tt>style.css</tt>. Now "test" is the parent Theme for "Rose", which still consists only of a <tt>style.css</tt> file and the concomitant images, all located in the directory <tt>wp-content/themes/Rose</tt>. ''(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.)'' 如果存在最簡單的主題,這種主題只包括一個<tt>style.css</tt>文件和圖像(如果有圖像)。要創(chuàng)建這樣的一個主題,你必須通過在<tt>style.css</tt>標題評論中編輯<tt>Template:</tt>行,來規(guī)定一套模板來''繼承''使用主題。例如,如果你想要"Rose"主題來繼承其它的一個稱作"測試"的主題的模板,你就會將評論中的<tt>Template: test</tt>放入Rose的tt>style.css</tt>開端?,F(xiàn)在"test" 是"Rose"的母主題,只包含有一個<tt>style.css</tt>文件和一個相關(guān)的圖像,都在<tt>wp-content/themes/Rose</tt>目錄中。''(注規(guī)定一個母主題會從主題&mdash中繼承''所有的''主題文件;意思是子主題目錄中的任何模板文件都會被忽視。)'' The comment header lines in <tt>style.css</tt> are required for WordPress to be able to identify a Theme and display it in the [[WordPress:Administration_Panels|Administration Panel]] under [[WordPress:Administration_Panels#Design_-_Change_the_Look_of_your_Blog|Design]] > [[WordPress:Administration_Panels#Themes|Themes]] as an available Theme option along with any other installed Themes. <tt>style.css</tt>中的評論標題行要求WordPress能夠辨別一個主題并且將主題顯示在[[WordPress:Administration_Panels#Design_-_Change_the_Look_of_your_Blog|設(shè)計]] > [[WordPress:Administration_Panels#Themes|主題]]下的[[WordPress:Administration_Panels|管理面板]]與其它安裝好的主題一起,作為可選擇的主題。 '''Note''' : ''When defining the parent Theme, in the <tt>Template:</tt> 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 <tt>Template: WordPress Default</tt>, but <tt>Template: default</tt>, because default is the directory of this Theme.'' '''注''' : ''當在評論標題的<tt>Template:</tt>部分定義一個母主題的時候,你必須使用那個樣式的目錄名。例如,將默認的WordPress主題用作母主題,不要寫成<tt>模板: WordPress 默認</tt>,要寫成<tt>模板: 默認</tt>,因為默認是這個主題的目錄。'' ===Functions File=== ===函數(shù) 文件=== A theme can optionally use a functions file, which resides in the theme subdirectory and is named <tt>functions.php</tt>. This file basically acts like a [[WordPress:Plugins|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ù)文件,這個文件在主題子目錄中,并且命名為<tt>functions.php</tt>。文件基本像一個[[WordPress:Plugins|插件]]那樣運行,而且如果文件呈現(xiàn)在你使用的主題中,會在WordPress初始化(管理網(wǎng)頁和外部網(wǎng)頁)的時候,自動載入。建議使用這個文件: * 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 *定義你的主題多個模板文件中使用的函數(shù) *設(shè)置一個管理界面,提供給用戶顏色,樣式,和你的主題的其它方面的選項 The "Default" WordPress theme contains a <tt>functions.php</tt> file that defines functions and an admin screen, so you might want to use it as a model. Since <tt>functions.php</tt> 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. "默認"WordPress主題包含一個<tt>functions.php</tt>文件,這個文件定義了函數(shù)和一個管理界面,這樣你可能想將這個文件用作一個模型。因為<tt>functions.php</tt>基本起一個插件的作用,[[WordPress:Function_Reference|函數(shù)_參考]]列表有你怎樣處理這個文件的更多的信息。 ===Theme Template Files=== ===主題模板文件=== [[WordPress:Stepping Into Templates|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. [[WordPress:Stepping Into Templates|模板]]是PHP原始文件,根據(jù)訪客要求,用來產(chǎn)生網(wǎng)頁的。讓我們來看看可以被定義為主題部分的不同的模板。 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 <tt>index.php</tt> 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能夠使你為你的博客的不同部分分別定義模板;然而,使你的博客正常地運行,并不一定需要所有的這些不同的模板文件。模板是根據(jù)[[WordPress:Template Hierarchy|模板層級]]選擇和產(chǎn)生的,取決于特別的主題中擁有什么樣的模板。作為一個主題開發(fā)者,你可以選擇你想使用模板,自定義多少內(nèi)容。例如,一個極端的例子,你可以為網(wǎng)絡(luò)日志上產(chǎn)生的和顯示的''所有的''網(wǎng)頁,只使用一個稱為<tt>index.php</tt>模板文件,作為模板。一個更加通常的用法是使用不同的模板文件產(chǎn)生不同的結(jié)果,允許最大化的自定義。 ===='''Basic Templates'''==== ===='''基本的模板'''==== At the very minimum, a WordPress Theme consists of two files: 在最小值的時候, WordPress主題包含有兩個文件: * <tt>style.css</tt> * <tt>index.php</tt> * <tt>style.css</tt> * <tt>index.php</tt> Both of these files go into the Theme's directory. The <tt>index.php</tt> [[WordPress:Stepping Into Templates|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. 這兩個文件都歸屬于主題的目錄。<tt>index.php</tt> [[WordPress:Stepping Into Templates|模板文件]]非常地靈活。它可以被用來包括關(guān)于標題,工具條,頁腳,內(nèi)容,類別,歸檔,搜索,錯誤和你的站點上的用戶創(chuàng)建的其它的網(wǎng)頁的所有參數(shù)?;蛘咚梢员?'再次地分''到模模板文件,每個部分都具有一部分的工作量。 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 <tt>comments.php</tt> or <tt>comments-popup.php</tt> template file, then WordPress will automatically use the <tt>wp-comments.php</tt> and <tt>wp-comments-popup.php</tt> 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: 如果你沒有提供其它任何的模板文件,WordPress會使用內(nèi)置的默認文件。例如,如果你既沒有<tt>comments.php</tt>也沒有<tt>comments-popup.php</tt>模板文件,WordPress就會使用[[WordPress:Template Hierarchy|模板層級]],自動地使用<tt>wp-comments.php</tt> 和<tt>wp-comments-popup.php</tt>模板文件。這些默認模板可能不太匹配你的主題,因此你可能需要提供你自己的模板。用來再次地切分的基本的文件(歸屬于主題的目錄)是: * <tt>header.php</tt> * <tt>sidebar.php</tt> * <tt>footer.php</tt> * <tt>comments.php</tt> * <tt>comments-popup.php</tt> * <tt>header.php</tt> * <tt>sidebar.php</tt> * <tt>footer.php</tt> * <tt>comments.php</tt> * <tt>comments-popup.php</tt> Using these modular template files, you can put template tags within the <tt>index.php</tt> master file to include or ''get'' these units where you want them to appear in the final generated web page. 使用這些模的模板文件,你可以將這些模板標簽放到<tt>index.php</tt>主要文件中來包括或者''得到''這些units,你想讓它們出現(xiàn)在最后產(chǎn)生的網(wǎng)頁的位置。 * To include the header, use the <tt>[[WordPress:Include Tags#The Header Template|get_header()]]</tt> template tag. *要包含標題,請使用<tt>[[WordPress:Include Tags#The Header Template|get_header()]]</tt>模板標簽。 * To include the sidebar, use the <tt>[[WordPress:Include Tags#The Sidebar Template|get_sidebar()]]</tt> template tag. *要包含工具條,使用<tt>[[WordPress:Include Tags#The Sidebar Template|get_sidebar()]]</tt>模板標簽。 * To include the footer, use the <tt>[[WordPress:Include Tags#The Footer Template|get_footer()]]</tt> template tag. *要包含頁腳,使用<tt>[[WordPress:Include Tags#The Footer Template|get_footer()]]</tt> 模板標簽。 Here is an example of the ''include'' usage: 下面是關(guān)于''包含'' 用法的一個例子: <pre><?php get_sidebar(); ?> <?php get_footer(); ?></pre> <pre><?php get_sidebar(); ?> <?php get_footer(); ?></pre> For more on how these various Templates work and how to generate different information within them, read the [[WordPress:Templates]] documentation. 關(guān)于這些不同模板怎樣運行以及怎樣在模板里面產(chǎn)生不同信息的更多內(nèi)容,請閱讀[[WordPress:Templates|模板]]文件。 ===='''Query-based Templates'''==== ===='''以查詢?yōu)榛A(chǔ)的模板'''==== WordPress can load different [[WordPress:Stepping Into Templates|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可以為不同的''查詢'' 形式載入不同的[[WordPress:Stepping Into Templates|模板]]。有兩種方法可以做到這一點:作為內(nèi)置的[[WordPress:Template Hierarchy|模板層級]]的一部分,通過在模板文件的[[WordPress:The Loop|Loop]]中使用[[WordPress:Conditional Tags|條件式標簽]]。 To use the [[WordPress:Template Hierarchy]], you basically need to provide special-purpose Template files, which will automatically be used to override <tt>index.php</tt>. For instance, if your Theme provides a template called <tt>category.php</tt> and a category is being queried, <tt>category.php</tt> will be loaded instead of <tt>index.php</tt>. If <tt>category.php</tt> is not present, <tt>index.php</tt> is used as usual. 要使用[[WordPress:Template Hierarchy|模板層級]],你只要提供特殊用途的模板文件,這個文件會自動地覆蓋<tt>index.php</tt>。例如,如果你的主題提供一個叫做<tt>category.php</tt>的模板,并且提供一個正被查詢的類別,<tt>category.php</tt>而不是<tt>index.php</tt>將會被載入。如果<tt>category.php</tt>沒有出現(xiàn),<tt>index.php</tt>會照常使用。 You can get even more specific in the Template Hierarchy by providing a file called, for instance, <tt>category-6.php</tt> -- this file will be used rather than <tt>category.php</tt> when generating the page for the category whose ID number is 6. (You can find category ID numbers in [[WordPress:Administration_Panels#Manage_-_Change_your_content|Manage]] > [[WordPress:Administration_Panels#Categories|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]]. 通過提供一個例如,稱作<tt>category-6.php</tt>的文件,你可以在模板層級中得到更加詳細的信息---當為一個ID號碼為6的類別產(chǎn)出網(wǎng)頁的時候,這個文件而不是<tt>category.php</tt>會被用到。(如果你在WordPress2.3版本以及更低的版本中,以站點管理員的身份登錄,你在 [[WordPress:Administration_Panels#Manage_-_Change_your_content|管理]] > [[WordPress:Administration_Panels#Categories|類別]] 下面會看到這個類別的ID數(shù)字。在WordPress 2.5版本中,管理面板中移除了ID欄。通過點擊'編輯類別' ,并且查找URL地址中的cat_ID 參數(shù)值,你可以查找類別id的位置。看起來就像'...categories.php?action=edit&cat_ID=3' 其中'3'就是類別 id)。更詳細地看看這個過程是怎樣進行的,請看看[[WordPress:Category Templates|類別模板]]。 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:The_Loop_in_Action|WordPress Loop]], and then you can load a particular template, or put some particular text on the screen, based on that condition. 如果你的主題需要更多地控制使用的哪個模板文件而不是[[WordPress:Template Hierarchy|模板層級]]中所提供的內(nèi)容,你可以使用[[WordPress:Template Hierarchy|條件式標簽]]。條件式標簽基本上是用來檢查看看在[[WordPress:The_Loop_in_Action|WordPress Loop]]內(nèi)的,一些特別的條件是否是真的,然后你就可以根據(jù)那個情況,載入一個特別的模板,或者在屏面上放一些特別的文本。 For example, to generate a distinctive style sheet in a post only found within a specific category, the code might look like this: 例如,給一個特別類別中的文章創(chuàng)建一個樣式表,代碼可能看起來像這樣的: <pre><?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'); } ?></pre> <pre><?php if (is_category(9)) { //查找類別9中的文章 包括(TEMPLATEPATH . '/single2.php'); } else { // 每隔一篇文章便放入這個 include(TEMPLATEPATH . '/single1.php'); } ?></pre> Or, using a query, it might look like this: 或者,使用一個查詢,這個查詢可能看起來像: <pre><?php $post = $wp_query->post; if ( in_category('9') ) { include(TEMPLATEPATH . '/single2.php'); } else { include(TEMPLATEPATH . '/single1.php'); } ?></pre> <pre><?php $post = $wp_query->post; if ( in_category('9') ) { include(TEMPLATEPATH . '/single2.php'); } else { include(TEMPLATEPATH . '/single1.php'); } ?></pre> 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. 在上述任一例子中,代碼會產(chǎn)生不同的模板,這些模板的使用取決于類別上顯示的文章。查詢條件并不局限于類別,然而—請看看[[WordPress:Conditional Tags|條件式標簽]]文章來看看所有的選項。 === Media Icons === === 媒體圖標 === '''This feature is [http://trac.wordpress.org/ticket/6751 currently broken in WordPress 2.5].''' '''這個功能[http://trac.wordpress.org/ticket/6751 當前在 WordPress 2.5中破壞了]。''' Wordpress uses media icons to represent [[WordPress:Using_Image_and_File_Attachments|attachment files]] on your blog and in the Admin interface, if those icons are available. WordPress使用媒體icons來代表你的博客和管理界面上的[[WordPress:Using_Image_and_File_Attachments|附屬文件]],前提是存在這些圖標。 It looks for image files named by media type in the <tt>images</tt> directory of the current theme. (As of Wordpress 2.2, the default theme comes with only one media icon, <tt>audio.jpg</tt>.) 它要查找當前主題的<tt>images</tt>目錄中的媒體類型所命名的圖像文件。(從Wordpress2.2開始,默認的主題只有一個媒體圖標,<tt>audio.jpg</tt>。) For example, for an attachment of [http://en.wikipedia.org/wiki/Internet_media_type MIME type] <tt>audio/mpeg</tt>, Wordpress would look for an icon file at these locations, stopping after the first match (see <tt>[[WordPress:Function_Reference/wp_mime_type_icon|wp_mime_type_icon]]</tt>): 例如,對于[http://en.wikipedia.org/wiki/Internet_media_type MIME 類型] <tt>audio/mpeg</tt>的一個附屬裝置,WordPress在這些位置中尋找一個圖標文件,在找到第一個匹配文件后,便停止(請看看<tt>[[WordPress:Function_Reference/wp_mime_type_icon|wp_mime_type_icon]]</tt>): # <var>my_theme</var>/images/audio.jpg # <var>my_theme</var>/images/audio.gif # <var>my_theme</var>/images/audio.png # <var>my_theme</var>/images/mpeg.jpg # <var>my_theme</var>/images/mpeg.gif # <var>my_theme</var>/images/mpeg.png # <var>my_theme</var>/images/audio_mpeg.jpg # <var>my_theme</var>/images/audio_mpeg.gif # <var>my_theme</var>/images/audio_mpeg.png # <var>my_theme</var>/images/audio.jpg # <var>my_theme</var>/images/audio.gif # <var>my_theme</var>/images/audio.png # <var>my_theme</var>/images/mpeg.jpg # <var>my_theme</var>/images/mpeg.gif # <var>my_theme</var>/images/mpeg.png # <var>my_theme</var>/images/audio_mpeg.jpg # <var>my_theme</var>/images/audio_mpeg.gif # <var>my_theme</var>/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 識別的主題模板文件的列表。當然,你的主題可以包含任何其它的樣式表,圖像,或者文件。''只要牢記下面的內(nèi)容對于WordPress具有一些特別的意義—更多的信息請看看[[WordPress:Template Hierarchy|模板層級]]。 '' ;<tt>style.css</tt>: The main stylesheet. This '''must''' be included with your Theme, and it must contain the information header for your Theme. ;<tt>style.css</tt>:主要的樣式表。這個'''必須'''包含在你的主題中,而且必須包含你的主題的信息標題。 ;<tt>index.php</tt>: The main template. If your Theme provides its own templates, <tt>index.php</tt> must be present. ;<tt>index.php</tt>:主要的模板。如果你的主題提供自己的模板,<tt>index.php</tt>必須呈現(xiàn)。 ;<tt>comments.php</tt>: The comments template. If not present, <tt>comments.php</tt> from the "default" Theme is used. ;<tt>comments.php</tt>:評論模板。如果沒有出現(xiàn),來自"默認"主題的<tt>comments.php</tt>就會被使用。 ;<tt>comments-popup.php</tt>: The popup comments template. If not present, <tt>comments-popup.php</tt> from the "default" Theme is used. ;<tt>comments-popup.php</tt>:彈出的評論模板。如果沒有出現(xiàn),來自"默認"主題的<tt>comments-popup.php</tt>就被使用。 ;<tt>home.php</tt>: The home page template. ;<tt>home.php</tt>: 主頁模板。 ;<tt>single.php</tt>: The single post template. Used when a single post is queried. For this and all other query templates, <tt>index.php</tt> is used if the query template is not present. ;<tt>single.php</tt>:單一的文章模板。當一篇單一的文章被查詢的時候,便會用到這個模板。對于這個和其它的查詢模板,如果查詢模板沒有出現(xiàn),就會用到<tt>index.php</tt>。 ;<tt>page.php</tt>: The page template. Used when an individual [[WordPress:Pages|Page]] is queried. ;<tt>page.php</tt>:網(wǎng)頁模板。當一個單獨的[[WordPress:Pages|網(wǎng)頁]]得到查詢的時候,便會用到這個。 ;<tt>category.php</tt>: The [[WordPress:Category Templates|category template]]. Used when a category is queried. ;<tt>category.php</tt>: The [[WordPress:Category Templates|類別模板]]。當詢問類別的時候,便會用到這個。 ;<tt>author.php</tt>: The [[WordPress:Author Templates|author template]]. Used when an author is queried. ;<tt>author.php</tt>:[[WordPress:Author Templates|作者模板]]。查詢作者的時候,會使用到這個。 ;<tt>date.php</tt>: The date/time template. Used when a date or time is queried. Year, month, day, hour, minute, second. ;<tt>date.php</tt>:日期/時間模板。當查詢?nèi)掌诨蛘邥r間的時候,便會用到這個模板。年,月,日,時,分,秒。 ;<tt>archive.php</tt>: The archive template. Used when a category, author, or date is queried. Note that this template will be overridden by <tt>category.php</tt>, <tt>author.php</tt>, and <tt>date.php</tt> for their respective query types. ;<tt>archive.php</tt>:歸檔模板。當查詢一個類別,作者或者日期的時候,便會用到這個模板。注意這個模板會被<tt>category.php</tt>, <tt>author.php</tt>, 和<tt>date.php</tt>各自的查詢形式覆蓋。 ;<tt>search.php</tt>: The search results template. Used when a search is performed. ;<tt>404.php</tt>: The '''[[WordPress:Creating_an_Error_404_Page|404 Not Found]]''' template. Used when WordPress cannot find a post or page that matches the query. ;<tt>search.php</tt>:搜索結(jié)果模板。當執(zhí)行一個搜索的時候,便會用到這個模板。 ;<tt>404.php</tt>:'''[[WordPress:Creating_an_Error_404_Page|404 沒有找到]]'''模板。當WordPress找不到匹配查詢的文章或者網(wǎng)頁的時候,便會用到這個模板。 These files have a special meaning with regard to WordPress because they are used as a replacement for <tt>index.php</tt>, when available, according to the [[WordPress:Template Hierarchy]], and when the corresponding [[WordPress:Conditional Tags|Conditional Tag]] (a.k.a <tt>is_*();</tt> function) returns true. For example, if only a single post is being displayed, the <tt>[[WordPress:Conditional Tags#A Single Post Page|is_single()]]</tt> function returns 'true', and, if there is a <tt>single.php</tt> file in the active Theme, that template is used to generate the page. 這些文件有關(guān)于WordPress的特別意思因為這些文件用來作為<tt>index.php</tt>替代品,條件是這些文件存在,根據(jù)[[WordPress:Template Hierarchy|模板層級]],而且相應(yīng)的[[WordPress:Conditional Tags|條件式標簽]] (a.k.a <tt>is_*();</tt> 函數(shù)) 返回是真。例如,如果只顯示一篇文章,<tt>[[WordPress:Conditional Tags#A Single Post Page|is_single()]]</tt>函數(shù)返回'真的',如果歸檔主題中有<tt>single.php</tt>文件,這個模板就用來創(chuàng)建網(wǎng)頁。 ===Referencing Files From a Template=== ===參考模板中的文件=== The WordPress Default Theme (based on Michael Heilemann's [http://binarybonsai.com/kubrick/ Kubrick] layout for WordPress 1.2) provides a good example of how queries are mapped onto templates. WordPress默認主題(以Michael Heilemann的[http://binarybonsai.com/kubrick/ Kubrick]WordPress1.2布局為基礎(chǔ))提供了一個非常好的例子,關(guān)于查詢是怎樣映射進模板的。 The code <tt><?php bloginfo('template_directory'); ?></tt> 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. 代碼<tt><?php bloginfo('template_directory'); ?></tt>將模板目錄的URL嵌入了模板輸出中。你可以將任何額外的URI信息添加到你的主題的參考文件的這個輸出中。 The code <tt><?php bloginfo('stylesheet_directory'); ?></tt> 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. 代碼<tt><?php bloginfo('stylesheet_directory'); ?></tt>嵌入了目錄的URI,這個URI將當前的主題樣式表包含到模板輸出中。你可以添加任何額外的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是當前主題模板目錄絕對路徑的一個參考(后面沒有/)。 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 <tt>images/</tt> directory in your Theme, you need only specify this relative directory in the CSS, like so: 注意用在樣式表中的URIs與樣式表相關(guān),但是與指代樣式表的網(wǎng)頁并不相關(guān)。這就避免了在CSS文件中包含PHP代碼來規(guī)定類別。例如,如果你的主題包含了一個<tt>images/</tt>目錄,你只需要在CSS中規(guī)定這個相關(guān)的目錄,像這樣的: <pre style="font-size: 0.9em">h1 { background-image: URL(images/my_background.jpg); }</pre> <pre style="font-size: 0.9em">h1 { background-image: URL(images/my_background.jpg); }</pre> 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. 對于模板中的參考文件以以上的方式使用URIs是一個好的做法,因為,這樣你的模板就不會依賴于絕對路徑了。 ===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 <tt>template_redirect</tt> [[WordPress:Plugin API#Current Hooks For Actions|action hook]]. More information about creating plugins can be found in the [[WordPress:Plugin API]] reference. 可以使用WordPress插件系統(tǒng)來定義額外的模板,這種模板以你自己自定義的標準,顯示。這個高級的功能通過使用<tt>template_redirect</tt> [[WordPress:Plugin API#Current Hooks For Actions|action hook]]可以得到實現(xiàn)。更多的關(guān)于創(chuàng)建插件的信息可以在[[WordPress:Plugin API|插件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è)置,這樣它就能夠很好地配合你(或者其它的主題用戶)可能決定安裝的WordPress插件。插件通過"Action Hooks"來給WordPress添加功能(請看看[[WordPress:Plugin API|插件API]]得到更多的信息)。大多數(shù)Action Hooks是在WordPress核心PHP代碼內(nèi)部,因此你的主題不要為它們的運行準備任何特別標簽。但是有幾個Action Hooks的確需要呈現(xiàn)在你的主題上,為了使插件能夠直接地在你的頁眉,頁腳,工具條,或者在網(wǎng)頁上顯示信息。下面是你需要的特別Action Hook模板標簽列表: ; wp_head ; wp_head : Goes in the [[WordPress:Glossary#HTML|HTML]] <tt><head></tt> element of a theme; <tt>header.php</tt> template. Example plugin use: add javascript code. : 進入 [[WordPress:Glossary#HTML|HTML]] <tt><head></tt> 主題元素; <tt>header.php</tt> 模板。例子插件使用: 添加 javascript 代碼。 : Usage: <tt><nowiki><?php do_action('wp_head'); ?></nowiki></tt> :''-or-'' <tt><nowiki><?php wp_head(); ?></nowiki></tt> : 用法: <tt><nowiki><?php do_action('wp_head'); ?></nowiki></tt> :''-or-'' <tt><nowiki><?php wp_head(); ?></nowiki></tt> ; wp_footer ; wp_footer : Goes in the "footer" of a theme; <tt>footer.php</tt> template. Example plugin use: insert PHP code that needs to run after everything else, at the bottom of the footer. : 進入主題的"頁腳"中; <tt>footer.php</tt> 模板。例子插件使用: 在頁腳的底部,嵌入需要在所有內(nèi)容運行之后運行的PHP代碼。 : Usage: <tt><nowiki><?php do_action('wp_footer'); ?></nowiki></tt> :''-or-'' <tt><nowiki><?php wp_footer(); ?></nowiki></tt> : 用法: <tt><nowiki><?php do_action('wp_footer'); ?></nowiki></tt> :''-or-'' <tt><nowiki><?php wp_footer(); ?></nowiki></tt> ; wp_meta ; wp_meta : Typically goes in the <tt><nowiki><li>Meta</li></nowiki></tt> section of a theme's menu or sidebar; <tt>sidebar.php</tt> template. Example plugin use: include a rotating advertisement or a tag cloud. : 通常進入主題的菜單或者工具條的<tt><nowiki><li>Meta</li></nowiki></tt>部分; <tt>sidebar.php</tt> 模板。 例子插件使用: 包括旋轉(zhuǎn)的廣告或者標簽cloud。 : Usage: <tt><nowiki><?php do_action('wp_meta'); ?></nowiki></tt> :''-or-'' <tt><nowiki><?php wp_meta(); ?></nowiki></tt> : 用法: <tt><nowiki><?php do_action('wp_meta'); ?></nowiki></tt> :''-or-'' <tt><nowiki><?php wp_meta(); ?></nowiki></tt> ; comment_form ; comment_form : Goes in <tt>comments.php</tt> and <tt>comments-popup.php</tt>, directly before the comment form's closing tag (<code><nowiki></form></nowiki></code>). Example plugin use: display a comment preview. : 進入 <tt>comments.php</tt> 和<tt>comments-popup.php</tt>中, 直接在評論形式的關(guān)閉標簽 (<code><nowiki></form></nowiki></code>)前面。 例子插件使用: 顯示一個評論預覽。 : Usage: <tt><nowiki><?php do_action('comment_form', $post->ID); ?></nowiki></tt> : 用法: <tt><nowiki><?php do_action('comment_form', $post->ID); ?></nowiki></tt> For a real world usage example, you'll find these plugin hooks included in the default theme's templates. 對于真實的世界用法的例子,你將會發(fā)現(xiàn)這些插件hooks包含在默認主題的模板中。 ==Theme Development General Guidelines== ==主題發(fā)展一般指導方針== Please be clear about the following in your documentation (a README file included with your Theme helps many users over any potential stumbling blocks): 請了解你的文件中的以下內(nèi)容(一個包含在你的主題中的README文件幫助許多用戶克服了許多潛在的問題): # Indicate precisely what your Theme and template files will achieve. #明確地指出你的主題和模板文件要獲得什么。 # Indicate deficiencies in your Themes, if any. #如果你的主題有什么缺陷的話,將它指出來。 # Clearly reference any special modifications in [[WordPress:Commenting_Code|comments]] within the template and style sheet files. Add comments to modifications, template sections, and CSS styles, especially those which cross template files. #明確地指出模板和樣式表文件中[[WordPress:Commenting_Code|評論]]任何特別的修改。給更改,模板部分,CSS樣式,特別是那些穿過模板文件的CSS樣式添加評論。 # 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,或者使用一些額外的,特別的模板,圖像或者文件,請清楚地描述用戶應(yīng)該采取那些措施,以使你的主題運行。 # Try and test your Theme [[WordPress:CSS_Fixing_Browser_Bugs|across browsers]] to catch at least a few of the [[WordPress:CSS_Troubleshooting|problems]] the users of the Theme may find later. #試著測試你的主題[[WordPress:CSS_Fixing_Browser_Bugs|跨越瀏覽器]]至少發(fā)現(xiàn)幾個,未來主題用戶可能碰到的[[WordPress:CSS_Troubleshooting|問題]]。 # Provide contact information (web page or email), if possible, for support information and questions. #如果可能的話,提供聯(lián)系信息(網(wǎng)頁或者電子郵件),來支持信息和問題。 Take time to read through [[WordPress:Designing Themes for Public Release]], an article with good tips on preparing your Theme for the public. 花一些時間來通讀[[WordPress:Designing Themes for Public Release|為了公共發(fā)行而設(shè)計主題]],這篇文章有許多關(guān)于怎樣準備你的主題來公共發(fā)行的好的貼士。 ==References and Resources== ==參考和資源== There is a comprehensive list of WordPress Theme and Template File resources in the [[WordPress:Templates]] article. 在[[WordPress:Templates|模板]]文章中有WordPress主題和模板文件資源。
摘要:
請注意,您對站長百科的所有貢獻都可能被其他貢獻者編輯,修改或刪除。如果您不希望您的文字被任意修改和再散布,請不要提交。
您同時也要向我們保證您所提交的內(nèi)容是您自己所作,或得自一個不受版權(quán)保護或相似自由的來源(參閱
Wordpress-mediawiki:版權(quán)
的細節(jié))。
未經(jīng)許可,請勿提交受版權(quán)保護的作品!
取消
編輯幫助
(在新窗口中打開)
取自“
http://kktzf.com.cn/wiki/Theme_Development
”