內容目錄
前言介紹
- 這款 WordPress 外掛「YAML Custom Fields」是 2025-12-31 上架。
- 目前尚無安裝啟用數,是個很新的外掛。如有要安裝使用,建議多測試確保功能沒問題!
- 上一次更新是 2026-02-05,距離現在已有 21 天。
- 外掛最低要求 WordPress 5.0 以上版本才可以安裝。
- 外掛要求網站主機運作至少需要 PHP 版本 8.1 以上。
- 尚未有人給過這款外掛評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
starbist |
外掛標籤
yaml | schema | frontmatter | meta fields | custom fields |
內容簡介
### 摘要:
YAML Custom Fields 允許您使用直觀的界面和類似 ACF 的模板功能來定義結構化內容模式。適合主題開發人員,他們希望在不增加複雜性的情況下進行靈活的、基於模式的內容管理。
### 問題與答案:
1. YAML Custom Fields 的特色有哪些?
- 定義頁面模板和模板部分的 YAML 結構
- 包括 15 種以上的字段類型,如字符串、富文本、圖像、塊、分類、數據對象等
- 易於使用的管理界面來管理結構和數據
- 三級數據層次結構:個別定制的每頁數據(存儲在文章元數據中)、模板全局數據(用於同一模板下所有文章)、全站全局數據(用於頁首和頁腳等)
- 每個字段可獨立使用模板全局數據或特定頁面數據的全域/局部切換
- 視覺化雙字段界面:同時查看模板全局和特定頁面值的對比
- 數據對象:用於管理結構化、可重用的數據(如大學、公司等)
- 數據驗證頁面:用於查看導入內容
- 整合的導出/導入頁面:支持所有數據類型的導出/導入
- 使用類似 ACF 語法的簡單模板功能和自動合併行為
- 只有管理員才能訪問以確保安全
- 清理卸載將刪除所有數據庫記錄
- 符合 WordPress 編碼標準
2. 支持的字段類型有哪些?
- 字符串、文本、富文本、代碼、布爾值、數字、日期、選擇、分類、帖子類型、數據對象、圖片、文件、對象、塊
3. 透過哪些範例可以使用 YAML Custom Fields?
- 在您的主題模板中通過 ycf_get_field 函數來獲取字段數值,例如英雄標題、圖像、類別等
- 透過 ycf_get_image 函數來獲取圖像字段和詳細信息
- 透過 ycf_get_file 函數來獲取文件字段和詳細信息
這些問題和答案將幫助您更好地了解 YAML Custom Fields 的功能和用途。
原文外掛簡介
YAML Custom Fields allows you to define structured content schemas with an intuitive interface and ACF-like template functions. Perfect for theme developers who want flexible, schema-based content management without the complexity.
Features
Define YAML schemas for page templates and template partials
15+ field types including string, rich-text, images, blocks, taxonomies, data objects, and more
Easy-to-use admin interface for managing schemas and data
Three-level data hierarchy:
Per-page data for individual customization (stored in post meta)
Per-template global data shared across all posts using the same template
Site-wide global data for partials like headers and footers
Per-field global/local toggle: Each field can independently use template global data or page-specific data
Visual dual-field interface: See both template global and page-specific values side-by-side
Data Objects for managing structured, reusable data (universities, companies, etc.)
Data Validation page for reviewing imported content
Consolidated Export/Import page for all data types (settings, page data, data objects)
Simple template functions with ACF-like syntax and auto-merge behavior
Administrator-only access for security
Clean uninstall removes all database records
WordPress Coding Standards compliant
Supported Field Types
String – Single-line text with min/max length
Text – Multi-line textarea
Rich Text – WordPress WYSIWYG editor
Code – Code editor with syntax highlighting
Boolean – Checkbox for true/false values
Number – Number input with min/max constraints
Date – Date picker with optional time
Select – Dropdown with single/multiple selection
Taxonomy – WordPress categories, tags, or custom taxonomies with single/multiple selection
Post Type – Dropdown to select registered post types (Post, Page, custom post types)
Data Object – Reference to structured data objects managed independently (universities, companies, team members, etc.)
Image – WordPress media uploader for images
File – WordPress media uploader for any file
Object – Nested group of fields
Block – Repeatable blocks for flexible page builders
Usage Example
In your theme template:
name); ?>
Developer Documentation
Template Functions
Get a single field value:
$value = ycf_get_field('field_name');
$value = ycf_get_field('field_name', 123); // Specific post ID
$value = ycf_get_field('logo', 'partial:header.php'); // From partial
$value = ycf_get_field('title', null, $block); // From block context
Get image field with details:
$image = ycf_get_image('field_name', null, 'full');
$image = ycf_get_image('field_name', 123, 'thumbnail'); // Specific post ID
$image = ycf_get_image('icon', null, 'medium', $block); // From block context
// Returns: array('id', 'url', 'alt', 'title', 'caption', 'description', 'width', 'height')
Get file field with details:
$file = ycf_get_file('field_name', null);
$file = ycf_get_file('field_name', 123); // Specific post ID
$file = ycf_get_file('document', null, $block); // From block context
// Returns: array('id', 'url', 'path', 'filename', 'filesize', 'mime_type', 'title')
Get taxonomy field (term or terms):
$term = ycf_get_term('field_name', null);
$term = ycf_get_term('field_name', 123); // Specific post ID
$term = ycf_get_term('category', null, $block); // From block context
// Returns: WP_Term object or array of WP_Term objects (for multiple selection)
Get post type field:
$post_type = ycf_get_post_type('field_name', null);
$post_type = ycf_get_post_type('field_name', 123); // Specific post ID
$post_type = ycf_get_post_type('content_type', null, $block); // From block context
// Returns: WP_Post_Type object or null
Get data object field:
$university = ycf_get_data_object('field_name', null);
$university = ycf_get_data_object('field_name', 123); // Specific post ID
$university = ycf_get_data_object('university', null, $block); // From block context
// Returns: Array with data object entry fields or null
Get all entries of a data object type:
$all_universities = ycf_get_data_objects('universities');
foreach ($all_universities as $entry_id => $university) {
echo esc_html($university['name']);
}
// Returns: Array of all entries for the specified data object type
Get all fields:
$fields = ycf_get_fields();
$fields = ycf_get_fields(123); // Specific post ID
$fields = ycf_get_fields('partial:footer.php'); // From partial
Check if field exists:
if (ycf_has_field('hero_title')) {
echo ycf_get_field('hero_title');
}
Working with Block fields:
$blocks = ycf_get_field('features');
if (!empty($blocks)) {
foreach ($blocks as $block) {
// Access nested fields using context_data parameter
$title = ycf_get_field('title', null, $block);
$icon = ycf_get_image('icon', null, 'thumbnail', $block);
$category = ycf_get_term('category', null, $block);
echo '
' . esc_html($title) . '
';
if ($icon) {
echo '';
}
if ($category) {
echo '' . esc_html($category->name) . '';
}
}
}
Sample YAML Schema
fields:
- name: hero_title
label: Hero Title
type: string
required: true
options:
maxlength: 100
- name: hero_image
label: Hero Image
type: image
- name: category
label: Category
type: taxonomy
options:
taxonomy: category
- name: tags
label: Tags
type: taxonomy
multiple: true
options:
taxonomy: post_tag
- name: content_type
label: Content Type
type: post_type
- name: university
label: University
type: data_object
options:
object_type: universities
- name: features
label: Features
type: block
list: true
blockKey: type
blocks:
- name: feature
label: Feature Block
fields:
- name: title
label: Title
type: string
- name: icon
label: Icon
type: image
- name: description
label: Description
type: text
Working with Partials
For custom partials, add the @ycf marker in the file header:
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「YAML Custom Fields」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
1.2.3 | 1.2.4 | 1.2.5 | 1.2.6 | trunk |
延伸相關外掛(你可能也想知道)
Static Site Exporter 》nclude information relevant to the issue you are reporting., , , 功能, , 將所有文章、頁面和 WordPress 設定轉換為 Markdown 和 YAML 格式,可用於 Jeky...。SyntaxHighlighter Evolved: Yaml Brush 》將 Yaml 語言的支援加入到 SyntaxHighlighter Evolved 外掛程式中。。
Theme YAML – Use YAML instead JSON for your theme.json settings and styles 》Theme Yaml 可以將您的 theme.yaml 檔案轉換為 theme.json,以便使用 YAML 配置您的主題。相較於 JSON,這樣的方式可以加注釋並且更簡潔明瞭。預設生成的 the...。
