2013-11-20 43 views
3

我想添加2個頁面模板(其中一個是我的默認頁面,另外一個),使用wordpress作爲一個CMS(內容管理系統)。我有2個PHP文件,一個名爲VM.php(我的默認頁面)和另一個lol.php(我只是在這裏測試,所以請原諒我有趣的網頁名稱)。在這兩個文件,在最上面我寫的腳本,它們對應的網頁:如何在WordPress中正確添加頁面模板?

<?php /* Template Name: VM */ ?> 

<?php /* Template Name: lol */ ?> 

正如你可以在下面的截圖中看到,我在的wp-content /主題的父文件夾這兩個文件以及在一個子文件夾wp-content/themes/my-theme(我試圖單獨使用子文件夾在父文件夾中沒有任何內容,以查看它是否可以正常工作,並且還通過刪除子文件夾來嘗試刪除子文件夾沒有工作)。

這裏是鏈接到舊的屏幕截圖:

http://s1228.photobucket.com/user/Ebadly/media/random/ScreenShot2013-11-20at12342PM_zps4b0c04d6.png.html 

我不知道我做錯了什麼,而是創建一個新的模板時,選擇頁面模板的選項沒有顯示出來。我在這裏錯過了什麼嗎?

編輯: 這是一個新的屏幕截圖,顯示我的主題文件夾的新層次:

Here is a new screen shot to show the new hierarchy of the my-theme folder:

回答

1

我想出了問題所在。爲了創建頁面模板,你必須至少有2個頁面,index.php和style.css(style.css中唯一需要的php註釋是Theme Name:your-theme-name)。

這樣做之後,你必須把這些4個文件成一個壓縮文件夾,然後前往外觀 - >主題,單擊該選項卡「安裝」的主題。上傳壓縮文件夾。然後你可以「激活」你的主題。安裝主題的最後一步將允許顯示「頁面模板」選項。

我討厭回答我的問題,但這是最後一步,我需要:安裝通過Zip文件夾的主題。謝謝大家的答案。

+0

確保你標記你的答案一旦你能夠這樣做,接受,讓其他人可以從你的經驗中受益。很高興它解決了。 –

+0

@PatJ是的,會做的,謝謝你! –

1

默認頁面模板page.php(如果不存在,index.php將被使用)這應該是在你的主題的根文件夾,並創建一個自定義頁面模板,你應當命名爲

page-{slug}.php 
// or 
page-{ID}.php 

,並把這個你的主題的根文件夾中了。例如,如果你想創建一個自定義頁面模板lol那麼它應該是保存使用名稱page-lol.php並把這個起初,這個模板文件,這將是在template組合框(Lol Page

<?php 
/* 
Template Name: Lol Page 
*/ 
可見

twentythirteen主題文件夾

wp-content 
    themes 
     twentythirteen 
     // other files 
     page.php 
     page-lol.php 
     style.css 
     // other filse 

截圖:Read more on Codex

enter image description here

更新:我不知道,如果你正在做的是正確的,如果你沒有一個style.css文件,然後WordPress不會承認你的主題,並在您style.css文件,你必須把一些資料(樣式表頭)以及(WP需要這些信息),這裏有一個例子(Read more on Codex

/* 
Theme Name: Twenty Thirteen 
Theme URI: http://wordpress.org/themes/twentythirteen 
Author: the WordPress team 
Author URI: http://wordpress.org/ 
Description: The 2013 theme for WordPress 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.1 
License: GNU General Public License v2 or later 
License URI: http://www.gnu.org/licenses/gpl-2.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: twentythirteen 

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. 
*/ 

此外,請確保您已經激活了您的主題,從管理面板Appearance -> Themes菜單。

+0

我改變VM.php到page.php文件和lol.php到頁面lol.php ...還是頁面下的模板屬性還沒有顯示出來。 –

+0

您是否首先添加了評論'Template Name:Lol Page'並且是您主題的根文件夾中的文件? –

+1

@EbadSaghar如果'VM.php'和'lol.php'文件不在有效的主題中(即,帶有'style.css'和'index.php'的文件),它們將不會顯示在模板下拉框。 –

1

它看起來像你在你的主題中缺少style.cssindex.php - 這兩個文件都是必需的。

my-theme添加這些,並確保把所需的意見在style.css

/* 
Theme Name: my-theme 
Theme URI: http://localhost/wordpress/my-theme 
Author: Me 
Author URI: http://wordpress.org/ 
etc ... 
*/ 

頂部的Codex

的評論標題行中的style.css需要讓WordPress能夠識別主題並將其顯示在設計>主題下的管理面板中作爲可用的主題選項以及任何其他已安裝的主題。

+0

style.css由什麼組成?我可以只是空白嗎? –

+0

另外,index.php呢?我也有那個空白。 –

+0

@EbadSaghar:只要你在'my_theme'目錄中都有'index.php'和'style.css',並且已經從'Appearance - > Themes'激活了你的主題,它應該可以工作。請注意,您將不會有與主題相關的圖像,例如默認的圖像,它只會列出您的主題名稱。 – 2013-11-20 22:12:58

2

你的截圖表明這樣的結構:

themes 
... 
    my-theme 
     lol.php 
     VM.php 

Codex page on Theme Development,我發現

在最低限度,一個WordPress主題包括兩個文件:

style.css

index.php

查看Template Hierarchy以及。請注意,您的主題應爲總是至少有一個index.php文件作爲默認模板文件(除非您正在編寫child theme)。

編輯

在最低限度,style.css文件應包含您的主題名稱:

/* 
Theme Name: [whatever you want to call your theme] 
*/ 

如果您還沒有通過Theme Development頁面上的食品閱讀(特別是Basic Templates部分)。

+0

我將style.css和index.php添加到my-theme文件夾中,其中包括其他2個php文件。我仍然沒有選擇選擇頁面模板的選項。 –

+0

當你有'style.css'和'index.php'文件時,你激活了主題嗎? –

+0

我該怎麼做?我去了左側wp-admin頁面的「主題」部分,但我沒有看到我的主題以激活它。 –

相關問題