askupa-software / amarkal-taxonomy
WordPress中分类的实用函数集合
dev-master
2017-12-25 21:20 UTC
Requires
- php: >=5.3.0
- askupa-software/amarkal-ui: dev-master
This package is not auto-updated.
Last update: 2024-09-14 20:20:14 UTC
README
WordPress中分类的实用函数集合。
已测试至: WordPress 4.7
依赖项: amarkal-ui
概述
amarkal-taxonomy 允许您向WordPress中的分类添加自定义字段,并且可选地向分类术语表中添加列。未来还将添加更多实用函数。
安装
通过Composer
如果您正在使用命令行
$ composer require askupa-software/amarkal-taxonomy:dev-master
或者只需将以下内容添加到您的 composer.json
文件中
"require": { "askupa-software/amarkal-taxonomy": "dev-master" }
然后运行命令
$ composer install
这将在目录 vendors/askupa-software/amarkal-taxonomy
中安装包。现在您只需要包含composer自动加载器。
require_once 'path/to/vendor/autoload.php';
手动安装
从github下载 amarkal-ui 和 amarkal-taxonomy,并将它们包含到您的项目中。
require_once 'path/to/amarkal-ui/bootstrap.php'; require_once 'path/to/amarkal-taxonomy/bootstrap.php';
参考
amarkal_taxonomy_add_field
向特定分类的添加和编辑表单中添加字段。
amarkal_taxonomy_add_field( $taxonomy_name, $field_type, $field_props )
此函数可用于向“添加术语”和“编辑术语”分类表单中添加字段。有关支持的字段类型,请参阅 amarkal-ui,或者使用 amarkal_ui_register_component
注册自己的字段类型。
参数
$taxonomy_name
(String) 指定分类名称,例如 'category'。$field_name
(String) 指定字段名称/ID。$field_props
(Array) 指定UI组件属性。此数组应包含在 amarkal-ui 中指定的原始UI组件属性,以及以下内容type
(String) 指定要添加的字段类型。它是核心amarkal-ui
组件之一或已注册的自定义组件。title
(String) 指定此字段的表单标题。description
(String) 指定将在字段下方打印的简短描述。table
(Array) 一个关联数组,具有以下参数show
(Boolean) 指定是否在分类术语表中为此字段添加列。sortable
(Boolean) 指定是否使此字段的列可排序。
示例用法
// Add a text field to the 'category' taxonomy 'add' & 'edit' forms: amarkal_taxonomy_add_field('category', 'cat_icon', array( 'type' => 'text', 'title' => 'Icon', 'description' => 'The category\'s icon', 'table' => array( 'show' => true, // Add a column to the terms table 'sortable' => true // Make that column sortable ) )); // Then you can retrieve the data using: $icon = get_term_meta( $term_id, 'cat_icon', true );