juvo / posttypes
简单的WordPress自定义文章类型。
dev-master
2023-03-05 19:21 UTC
Requires
- php: >=7.4
Requires (Dev)
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.7
- phpunit/phpunit: 9.*
- squizlabs/php_codesniffer: 3.*
- szepeviktor/phpstan-wordpress: ^1.1
This package is auto-updated.
Last update: 2024-09-15 04:42:16 UTC
README
基于Joe Grainger工作的简单WordPress自定义文章类型库。
要求
安装
使用Composer安装
在您的终端中运行以下命令以使用Composer安装PostTypes。
$ composer require juvo/posttypes
PostTypes使用PSR-4自动加载,并可以使用Composer的自动加载器。以下是一个基本示例,但您的配置可能因您使用Composer的方式而异。
require __DIR__ . '/vendor/autoload.php'; use PostTypes\PostType; $books = new PostType( 'book' ); $books->register();
有关与Composer和自动加载一起使用的基本使用说明,请参阅Composer的基本使用指南。
基本使用
以下是一个设置简单书籍文章类型和类型分类的示例。有关更多信息,请参阅此处的在线文档。
// Require the Composer autoloader. require __DIR__ . '/vendor/autoload.php'; // Import PostTypes. use PostTypes\PostType; use PostTypes\Taxonomy; // Create a book post type. $books = new PostType( 'book' ); // Attach the genre taxonomy (which is created below). $books->taxonomy( 'genre' ); // Hide the date and author columns. $books->columns()->hide( [ 'date', 'author' ] ); // Set the Books menu icon. $books->icon( 'dashicons-book-alt' ); // Add custom capabilities $books->capabilities([], ['editor', 'author']); // Register the post type to WordPress. $books->register(); // Create a genre taxonomy. $genres = new Taxonomy( 'genre' ); // Set options for the taxonomy. $genres->options( [ 'hierarchical' => false, ] ); // Register the taxonomy to WordPress. $genres->register();
注意
- 完整文档可在posttypes.jjgrainger.co.uk上找到
- 该类没有为文章类型创建自定义字段的方法,请使用Advanced Custom Fields
- README.md中使用的书籍示例可在examples/books.php中找到
- 基于MIT许可证
- 根据语义化版本控制指南维护
原始作者
Joe Grainger