underpin/taxonomy-loader

Underpin的分类加载器

1.1.0 2021-11-24 21:42 UTC

This package is auto-updated.

Last update: 2024-08-25 03:49:35 UTC


README

一个辅助在WordPress网站上注册分类分类的加载器。

安装

使用Composer

composer require underpin/taxonomy-loader

手动

此插件使用内置的自动加载器,所以只要它在Underpin之前被要求,它应该按预期工作。

require_once(__DIR__ . '/underpin-taxonomies/taxonomies.php');

设置

  1. 安装Underpin。请参阅Underpin文档
  2. 根据需要注册新的分类菜单。

示例

一个非常基础的例子可能看起来像这样。

// Register taxonomy
underpin()->taxonomies()->add( 'taxonomy', [
	'post_type'   => 'post',                        // Defaults to post.
	'id'          => 'ingredients',                 // Required. See register_taxonomy
	'description' => 'Ingredients for this recipe', // Human-readable description.
	'name'        => 'Ingredients',                 // Human-readable name. Usually plural. Will set "label" argument if name is unset in args.
	'args'        => [                              // Default atts. See register_taxonomy
		'public' => true,
	],
] );

或者,您可以扩展Taxonomy并直接引用扩展类,如下所示

underpin()->taxonomies()->add('taxonomy-key','Namespace\To\Class');

查询

一个分类实例包含一个名为query的方法,它作为new WP_Term_Query的包装器。

这封装了此分类的查询,并为您提供了一个可以覆盖查询方式的位置,如果您决定扩展类。

underpin()->taxonomies()->get( 'taxonomy' )->query();

编辑术语

与查询类似,分类实例包含一个名为save的方法,它作为wp_insert_termwp_update_term的包装器。它还包括通知记录,以便您可以跟踪请求中的发生情况。

这封装了此分类的保存操作,并为您提供了一个可以覆盖保存方式的位置,如果您决定扩展类。

underpin()->taxonomies()->get( 'taxonomy' )->save( [/* see wp_insert_post */] );

删除术语

这和savequery的工作方式相同。它包括日志记录,并提供了一种封装操作的方法。

underpin()->taxonomies()->get( 'taxonomy' )->delete( $term );