Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124

原本頁面(Page)的範本有幾種: 預設範本、Full、Large 、Medium、Small width template 及 Page with sidebar 這幾種。

最標準最常用的做法是 Page Template
在「wp-content->themes->yourTheme」建立一個PHP檔案,例如:page-my-custom.php,表頭標示如下
<?php
/*
Template Name: Custom My Page
*/
get_header();
?>
<h1>這是自訂頁面</h1>
<?php get_footer(); ?>右側的 模板 / Template 選擇 Custom Page,這樣這個 Page 就會使用 page-custom.php

在前端的顯示

如果想讓某頁固定對應某檔案,例如:
mycustompage-mycustom.php那 WordPress 會自動套用這個檔案。
page-{slug}.php
例如:
page-mycustom.php建一個PHP檔名: page-mycustom.php

如果該頁 slug 是 mycustom,WordPress 會自動讀這支程式,如下圖。

在 page.php 裡:
<?php
if (is_page('about')) {
include get_template_directory() . '/custom/about-template.php';
return;
}
get_header();
while (have_posts()) : the_post();
the_content();
endwhile;
get_footer();這樣當頁面是 about 時,就改載入指定 PHP。
主模板只是入口,真正畫面在別的 PHP 檔。
<?php
/*
Template Name: Contact Page
*/
include get_template_directory() . '/templates/contact.php';如果是要:
page-{slug}.php像這種不是 WordPress 正規做法:
/abc/test.php這通常不建議,因為會繞過 WordPress 的:
假設要「聯絡我們」這頁指向指定 PHP:
page-contact.php<?php
get_header();
?>
<h2>聯絡我們</h2>
<p>這是 contact 頁面</p>
<?php get_footer(); ?>然後該頁 slug 設成 contact
template-contact.php
<?php
/*
Template Name: Contact Template
*/
get_header();
?>
<h2>聯絡我們</h2>
<?php get_footer(); ?>後台該 page 選 Contact Template