vendi-advertising/vendi-cpt-from-yaml

从yaml文件加载CPT

v2.0.5 2023-06-20 14:08 UTC

This package is auto-updated.

Last update: 2024-09-20 17:32:38 UTC


README

PHP Composer codecov

Vendi将CPT信息存储在YAML文件中,并使用此库进行解析和加载CPT。虽然这样做会有轻微的开销,但前端缓存可以完全抵消这一点。对于没有前端缓存的网站,可以将YAML文件进一步解析并存储在临时存储中。

位置和文件名

配置文件通常存储在主题根目录下的.config文件夹中,文件名为cpts.yaml。您还可以创建一个名为CPT_YAML_FILE的环境变量,该变量指向配置文件的绝对路径,或指向主题目录的相对路径。

选项

文件格式非常简单,适用于CPT的99%用例。YAML文件中没有传统register_post_type WordPress函数不可用的功能。

  • 根键是CPT的WordPress别名
    • 由于这是一个别名,就像任何其他CPT一样,一旦定义后不应更改,否则现有内容可能会丢失。
  • 两个必需的子键是singularplural,它们控制CPT的显示名称。
  • 两个可选子键是singular_lowercaseplural_lowercase,如果没有提供,它们将自动生成。
  • 最后一个可选子键是extended_options,其值直接映射到核心WordPress函数register_post_type

示例

# The slug for our alert CPTs
alert:
    # Singular and plural human-readable versions
    singular: Alert
    plural: Alerts

    # The contents of this key are merged with the required WordPress labels and passed directly
    # as the second argument to the register_post_type function. Common default values for these
    # items are set in https://github.com/vendi-advertising/vendi-cpt-from-yaml/blob/f85a3db005da11f88b9e5340ba12202b86584f81/src/CPTBase.php#L160
    extended_options:
        supports:
            - title
            - editor
        public: true
        has_archive: false
        menu_icon: dashicons-visibility
        exclude_from_search: true
        publicly_queryable: false