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