百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

models

> 编程语言
开源

使用 JSON、YAML 或 PHP 文件创建自定义文章类型和分类的 WordPress 插件

172 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

使用 JSON、YAML 或 PHP 文件创建自定义文章类型和分类的 WordPress 插件

Models

Models is a WordPress plugin allowing you to create custom post types and taxonomies using JSON, YAML or PHP files.

You can now set post types and taxonomies using Intervention 2.x.x.

Installation

Composer:

Recommended methods:

Roots Bedrock

bash
$ composer require soberwp/models:1.1.0

Models is a mu-plugin so it doesn't have to be activated.

Roots Sage

bash
$ composer require soberwp/models:1.1.0-p

Manual:

  • Download the zip file
  • Unzip to your sites plugin folder
  • Activate via WordPress

Requirements:

  • PHP >= 5.6.x

Setup

By default, create folder models/ within the active theme directory.

If you are a Roots Sage the default folder is app/models/

Alternatively, you can define a custom path using the filter below within your themes functions.php file:

php
add_filter('sober/models/path', function () {
    return get_stylesheet_directory() . '/your-custom-folder';
});

That's it, now go ahead and add model-name.json files, in the folder or subfolders to begin creating your models. Use Unravel to automatically move the config files outside of your theme path for better separation of concerns.

Usage

The data structure follows a similar data structure to WordPress taxonomies and post types arrays, so if an config option is missing from the examples below, follow the developer's reference and place it within "config": {}

If values are not specified, defaults are the same as WordPress defaults.

Additionally, if the Extended CPTs library is available, Models will use it when registering your post types and taxonomies instead allowing extended functionality within your Models.

Extracted examples presented below are in JSON format.

Post Types

Create a custom post type.

Required:

  • post-type-required.json
  • post-type-required.php
  • post-type-required.yaml
json
{
  "type": "post-type",
  "name": "book"
}

Basic:

  • post-type-basic.json
  • post-type-basic.php
  • post-type-basic.yaml
json
{
  "type": "cpt",
  "name": "book",
  "supports": [
    "title", "editor", "thumbnail"
  ],
  "labels": {
    "has_one": "Book",
    "has_many": "Books",
    "text_domain": "sage"
  }
}

In the above example, "labels": {} are redundant because "Book" and "Books" would have been generated from "name".

Multiple:

  • post-type-multiple.json
  • post-type-multiple.php
  • post-type-multiple.yaml
json
[
  {
    "type": "cpt",
    "name": "book",
    "supports": [
      "title", "editor", "thumbnail"
    ]
  },
  {
    "type": "cpt",
    "name": "album",
    "supports": [
      "title", "editor", "comments"
    ]
  }
]

All Fields:

  • post-type-all.json
  • post-type-all.php
  • post-type-all.yaml

Post Type Tips:

  • "active": false stops the post type from being created. Default is set to true.
  • "type": "post-type" also accepts a shorthand "type": "cpt";

Taxonomies

Create a custom taxonomy.

Required:

  • taxonomy-required.json
  • taxonomy-required.php
  • taxonomy-required.yaml
json
{
  "type": "taxonomy",
  "name": "genre"
}

Basic:

  • taxonomy-basic.json
  • taxonomy-basic.php
  • taxonomy-basic.yaml
json
{
  "type": "tax",
  "name": "genre",
  "links": [
    "post", "book"
  ],
  "labels": {
    "has_one": "Book Genre",
    "has_many": "Book Genres",
    "text_domain": "sage"
  }
}

"links": (string|array) assigns the taxonomy to post types. Defaults to "links": "post"

Multiple:

  • taxonomy-multiple.json
  • taxonomy-multiple.php
  • taxonomy-multiple.yaml
json
[
  {
    "type": "category",
    "name": "genre",
    "links": "book"
  },
  {
    "type": "tag",
    "name": "author",
    "links": "book"
  }
]

"type": "category" and "type": "tag" shorthands are explained below under Tips.

All Fields:

  • taxonomy-all.json
  • taxonomy-all.php
  • taxonomy-all.yaml

Taxonomy Tips:

  • "active": false stops the taxonomy from being created. Default is set to true.
  • "type": "taxonomy" also accepts shorthands;
    • "type": "tax"
    • "type": "category" or "type": "cat" creates a category taxonomy.
    • "type": "tag" creates a tag taxonomy.

Support

  • Follow @withjacoby on Twitter
  • Buy me a beer or pay my rent, paypal.me/darrenjacoby

Updates

Composer:

  • Change the composer.json version to ^1.0.4**
  • Check CHANGELOG.md for any breaking changes before updating.
bash
$ composer update

WordPress:

Includes support for github-updater to keep track on updates through the WordPress backend.

  • Download github-updater
  • Clone github-updater to your sites plugins/ folder
  • Activate via WordPress

Issues· 2 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPjsonjson-configurationphpwordpress

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言