jjgrainger/posttypes

简单的WordPress自定义文章类型。

v2.2 2022-05-21 14:15 UTC

This package is auto-updated.

Last update: 2024-09-14 01:27:36 UTC


README

tests codecov Latest Stable Version Total Downloads License

简单的WordPress自定义文章类型。

要求

安装

使用Composer安装

在您的终端中运行以下命令以使用Composer安装PostTypes。

$ composer require jjgrainger/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' );

// 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();

注意

作者

Joe Grainger