azi/raskoh

Raskoh - 简化 WordPress CPT 和 Taxonomy 注册

1.4.1 2017-09-21 04:51 UTC

This package is auto-updated.

Last update: 2024-09-15 07:50:54 UTC


README

在 WordPress 中注册自定义帖子类型和分类法不再是头疼的问题。Raskoh 将使您的生活更简单。

Usage in theme functions.php

安装

您可以通过下载包并将其拉入 wp-content/plugins 文件夹或使用 composer 来安装 Raskoh 作为 WordPress 插件。

composer.json 文件中粘贴以下内容

{
   "require" : {
        "azi/raskoh" : "1.*"
   }
}

或者只需在您的项目中运行此命令。 $ composer require azi/raskoh

在主题的 functions.php 文件中包含 composer 的自动加载器

require_once "vendor/autoloader.php";

用法

注册帖子类型

要注册帖子类型

$music = new Raskoh\PostType("Music");
$music->register();
添加分类法

注册与帖子类型一起的分类法

$music = Raskoh\PostType::getInstance("Music");
$music->taxonomy('Singer')->register();
按术语限制帖子

如果您想在 WordPress 管理界面中添加术语下拉框以按术语限制帖子,只需将第二个布尔值传递给 php PostType::taxonomy($name, $filters = false) 方法即可。

$music = Raskoh\PostType::getInstance("Music");
$music->taxonomy('Singer', true)->register();
注册多个分类法
$music = Raskoh\PostType::getInstance("Music");
$music->taxonomy(['singer','genre'])->register();
设置图标

您还可以为帖子类型设置图标

$music = Raskoh\PostType::getInstance("Music");
$music->taxonomy('Singer')->setIcon('dashicons-format-audioy')->register();

您还可以像这样传递 wp_register_post_type() Codex 中列出的所有其他参数

$CPT = Raskoh\PostType::getInstance();
$CPT->set{ArgumentName}