Skip to content

WNCMS Theme Config 規格

本文件定義每個 WNCMS theme 中 config.php 的完整結構與使用方式。

theme config 包含:

  1. Theme metadata (info)
  2. Theme option 群組 (option_tabs)
  3. 預設值 (default)

1. info — Theme Metadata

結構

KeyTypeRequiredDescription
labelstringyesTheme 顯示名稱
namestringyesTheme ID,與資料夾名稱相同
authorstringyes建立者名稱
descriptionstringyes簡短描述
versionstringyesSemantic version (例如 1.0.0)
created_atstringyesYYYY-MM-DD
updated_atstringyes最後更新日期

範例

php
'info' => [
    'label'       => 'WNCMS Starter Theme',
    'name'        => 'starter',
    'author'      => 'Winnie',
    'description' => 'Official WNCMS base theme',
    'version'     => '1.0.0',
    'created_at'  => '2025-01-01',
    'updated_at'  => '2025-12-01',
],

2. option_tabs — Option 群組

option_tabs 是多分頁佈局,每個分頁包含多個輸入選項。

範例:

php
'option_tabs' => [
    'general' => [
        [
            'label' => 'General Settings',
            'type'  => 'heading',
        ],
        [
            'label' => 'Subtitle',
            'name'  => 'subtitle',
            'type'  => 'text',
        ],
    ],
],

Field Types 參考

每種 field type 支援不同的 keys。 以下是所有支援的 types 與表格和範例。

Basic Text & Number

text

KeyTypeRequiredExample
labelstringyes"Site Name"
namestringyes"site_name"
typestringyes"text"
defaultstringno"My Website"
descriptionstringno"Shown in header"

範例:

php
[
    'label' => 'Site Name',
    'name'  => 'site_name',
    'type'  => 'text',
],

類型切換相容(Array -> Text / Textarea)

當模板選項從陣列型欄位(例如 galleryaccordion)切換成 texttextarea 時:

  • 舊資料中的 JSON 陣列/物件會在編輯表單保留為原始 JSON 字串。
  • 頁面編輯時,標量欄位不再強制把 JSON 字串解碼成陣列。
  • 再次儲存頁面後,該欄位會以純文字寫回。

轉換預期範例:

  • 舊類型:gallery
  • 舊儲存值:[{"image":"/uploads/a.jpg","text":"A","url":""}]
  • 新類型:text
  • 編輯表單顯示:[{"image":"/uploads/a.jpg","text":"A","url":""}](字串)
  • 儲存後(若改為 Homepage hero):儲存值變成 Homepage hero

number

KeyTypeRequiredExample
labelstringyes"Items per page"
namestringyes"per_page"
typestringyes"number"
defaultintno12

範例:

php
[
    'label' => 'Items per page',
    'name'  => 'per_page',
    'type'  => 'number',
],

Media / Image

image

KeyTypeRequiredExample
labelstringyes"Top Banner"
namestringyes"banner"
typestringyes"image"
widthint/stringno800 / "50%" / "auto"
heightint/stringno300 / "auto"
aspect_ratiostringno"16/9"

行為:

  • 若僅設定 width → height 透過 aspect ratio 自動計算
  • 若僅設定 height → width 自動計算
  • 若兩者皆未設定 → 預設 width 400px,height auto

範例:

php
[
    'label' => 'Homepage Banner',
    'name'  => 'home_banner',
    'type'  => 'image',
    'width' => 800,
    'aspect_ratio' => '16/9',
],

display_image (Static Preview Image)

KeyTypeRequiredExample
labelstringyes"Preview"
typestringyes"display_image"
pathstringyes"theme/starter/images/demo.png"
widthint/stringno300 / "100%"
heightint/stringno120
aspect_ratiostringno"4/3"
colstringno"col-12 col-md-4"

行為:

  • 儲存資料
  • 僅用於 admin 預覽圖片
  • 若 width/height 未設定 → width=100%,height=auto
  • col 支援 Bootstrap grid

範例:

php
[
    'label' => 'Ad Slot Preview',
    'type'  => 'display_image',
    'path'  => 'starter/images/hero-demo.png',
    'col'   => 'col-12 col-md-4',
],

Gallery (Multiple Images)

KeyTypeRequiredExample
labelstringyes"Gallery"
namestringyes"hero_gallery"
typestringyes"gallery"
desktop_columnsintno4
mobile_columnsintno2
widthint/stringno300 / "50%"
heightint/stringno"auto"
aspect_ratiostringno"1/1"

儲存值範例:

json
[
  { "image": "/uploads/a.jpg", "text": "", "url": "" },
  { "image": "/uploads/b.jpg", "text": "", "url": "" }
]

Config 範例:

php
[
    'label' => 'Homepage Gallery',
    'name'  => 'hero_gallery',
    'type'  => 'gallery',
    'desktop_columns' => 4,
    'mobile_columns'  => 2,
    'aspect_ratio'    => '1/1',
],

Select / Boolean

select

KeyTypeRequiredExample
labelstringyes"Category"
namestringyes"category"
typestringyes"select"
optionsarray/stringyes["A","B"] or "posts" or "menus"
tag_typestringno"post_category"

範例:

php
[
    'label'   => 'Category',
    'name'    => 'category',
    'type'    => 'select',
    'options' => 'posts',
],

boolean

KeyTypeRequiredExample
labelstringyes"Show Banner?"
namestringyes"show_banner"
typestringyes"boolean"
defaultintno1

Textarea

textarea

KeyTypeRequiredExample
labelstringyes"About"
namestringyes"about"
typestringyes"textarea"
defaultstringno""

Color

color

KeyTypeRequiredExample
labelstringyes"Brand"
namestringyes"brand"
typestringyes"color"
requiredboolnotrue
placeholderstringno"#FFA218"
defaultstringno"#FFA218"

行為:

  • 顏色輸入現在支援 required 與 placeholder。
  • 為空時顯示預設值 #FFA218

Repeater

repeater

KeyTypeRequiredExample
labelstringyes"Slides"
namestringyes"hero_slides"
typestringyes"repeater"
fieldsarrayyes欄位定義
add_labelstringno"Add Slide"

行為:

  • Repeater JS 改為載入本地 wncms/js/jquery.repeater.min.js(不再使用 CDN)。
  • Starter Repeater 列使用防溢出排版(overflow-auto),避免水平裁切。

fields 支援簡單輸入定義:

php
[
    'label' => 'Hero Slides',
    'name' => 'hero_slides',
    'type' => 'repeater',
    'fields' => [
        ['name' => 'text', 'type' => 'text', 'label' => 'Text'],
        ['name' => 'number', 'type' => 'number', 'label' => 'Number'],
    ],
]

Editor (TinyMCE)

editor

KeyTypeRequiredExample
labelstringyes"Content"
namestringyes"content"
typestringyes"editor"

Structure Layout

heading

KeyTypeRequiredExample
labelstringyes"General Settings"
typestringyes"heading"
descriptionstringno"Section description"

sub_heading

KeyTypeRequiredExample
labelstringyes"Homepage Banner"
typestringyes"sub_heading"

inline

KeyTypeRequiredExample
labelstringyes"Three Columns"
namestringyes"stats"
typestringyes"inline"
sub_itemsarrayyesmultiple inputs
repeatintno3

accordion

KeyTypeRequiredExample
labelstringyes"FAQ"
namestringyes"faq_items"
typestringyes"accordion"
contentarrayyesfields inside FAQ
sortableboolnotrue
repeatintno3

Hidden

hidden

KeyTypeRequiredExample
labelstringno""
namestringyes"token"
typestringyes"hidden"
defaultstringyes"123"

3. default — 預設值

範例:

php
'default' => [
    'site_name' => 'My Website',
    'subtitle'  => 'Just another WNCMS site',
    'show_banner' => 1,
],

用 ❤️ 製作,獻給 WNCMS