wp-orbit/post-types
此包最新版本(dev-master)的许可证信息不可用。
WordPress帖子类型助手。
dev-master
2017-10-06 15:42 UTC
This package is not auto-updated.
Last update: 2024-09-26 08:50:26 UTC
README
通过 WP Orbit
PostType 类
此包提供了一个可扩展的 PostType 类,用于抽象化创建自定义帖子类型。
基本用法
对于每个所需的自定义帖子类型,扩展基础 PostType 类,然后调用 registerPostType()。
<?php use WPOrbit\PostTypes\PostType; // Extend PostType class AuthorPostType extends PostType { protected function __construct() { $this->key = 'author'; $this->slug = 'authors'; $this->singular = 'Author'; $this->plural = 'Authors'; } } class BookPostType extends PostType { protected function __construct() { $this->key = 'book'; $this->slug = 'books'; $this->singular = 'Book'; $this->plural = 'Books'; } } // Hook into WordPress... AuthorPostType::getInstance()->registerPostType(); BookPostType::getInstance()->registerPostType();
帖子类型支持
默认情况下,该类设置为支持:'标题'、'编辑器'、'作者'和'缩略图'。在扩展类的构造函数中覆盖 $this->supports 以添加其他默认功能到您的帖子类型。
<?php protected function __construct() { $this->key = 'book'; $this->slug = 'books'; $this->singular = 'Book'; $this->plural = 'Books'; $this->supports = ['title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments']; }