本專欄介紹如何開發設計你本身的 WordPress 主題。若是你但願瞭解更多如何安裝和應用主題的內容,請參閱應用主題文檔。本文的內容不一樣於應用主題,由於所討論的是編寫代碼去構建你本身的主題的技術內容,而非怎樣去激活主題或者是哪裏能夠得到新主題。php
WordPress 主題由一系列文件和 CSS 樣式表構成,構成了一個美麗的 WordPress 網站。每一個主題都是不一樣的, 這樣WordPress用戶就能夠隨時更改 WordPress 網站的外觀。css
你也許想爲本身開發 WordPress 主題,或者製做公開發行的的主題。可是除了這個爲何要本身製做主題呢?html
WordPress 主題有不少優勢.數據庫
爲何要本身製做主題呢?這纔是問題的關鍵.網絡
WordPress 主題應該按照以下標準開發:ide
WordPress主題目錄位於 wp-content/themes/
。主題的子目錄擁有全部樣式文件、模板文件、可選的函數文件 (functions.php
)、JavaScript 文件、圖片等。好比說一個叫作 "test" 的主題就會放在 wp-content/themes/test/
目錄裏。請避免使用數字名字,這會致使沒法在主題列表中正常顯示出來。wordpress
WordPress每個發行版都會有一個默認的主題。請認真查看默認的主題,這樣可能會對製做你本身的主題有幫助。函數
WordPress 主題除了圖片和JavaScript,常常由三種文件構成。oop
style.css
, 控制着頁面的外觀functions.php
)。讓咱們單獨看一下。post
CSS文件不只定義了你的主題樣式,style.css *必須 以註釋的形式列出主題的詳細信息。*兩個不一樣的主題是不容許擁有相同的表述的 , 由於這樣會致使主題選擇出錯.若是你經過拷貝一個你已經制做的主題來製做你新的主題,請確保先更改這些頭部註釋.
下面是樣式表頭部註釋的例子,被稱做樣式表頭註釋。好比主題"Bachelor":
/* Theme Name: Bachelor Theme URI: http://taper.io/themes/bachelor Author: Ayuan Author URI: http://taper.io/ Description: The Bachelor theme for TaperLabs takes us back to the blog, featuring a full range of post formats, each displayed beautifully in their own unique way. Design details abound, starting with a vibrant color scheme and matching header images, beautiful typography and icons, and a flexible layout that looks great on any device, big or small. Version: 1.0 License: GNU General Public License v3 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html Tags: black, brown, orange, tan, white, yellow, light, one-column, two-columns, right-sidebar, flexible-width, custom-header, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, translation-ready Text Domain: bachelor This theme, like WordPress, is licensed under the GPL. Use it to make something cool, have fun, and share what you've learned with others. */
在接下來的文章裏,我將從 WordPress 主題文件結構開始,講解並建立實例來分別討論函數文件、模板文件、基本模板、自定義頁面模板、搜索查詢模板、定義模板、模板的引用、插件 API 鉤子等的用法及機制。快速簡單的入門到了解這一方便簡潔的開源 CMS 系統中。