kunoichi/term-meta

一个用于轻松处理术语元数据的实用工具。

安装数: 2,033

依赖者: 0

建议者: 0

安全性: 0

星星: 0

关注者: 1

分支: 0

公开问题: 0

类型:wordpress-library

0.8.1 2019-09-11 05:16 UTC

This package is auto-updated.

Last update: 2024-09-11 16:54:50 UTC


README

一个用于轻松处理术语元数据的 WordPress 实用工具。

安装

composer require kunoichi/term-meta

使用方法

在你的主题的 functions.php

if ( class_exists( 'Kunoichi\TermMeta\ColorMeta' ) ) {
	new Kunoichi\TermMeta\ColorMeta( 'category_color', 'category', [
		'label'        => __( 'Color', 'your-domain' ),
		'admin_column' => true,
	] );
}

要获取此颜色,请使用 WordPress 内置函数 get_term_meta( $term_id, $meta_key, $single )

<?php
// For example, display category title
// with specified background color
// in category archive.
$color = get_term_meta( get_queried_object_id(), 'category_color', true ) ?: '#000';
?>
<h1 style="background-color: <?php echo esc_attr( $color ) ?>">
	<?php the_archive_title(); ?>
</h1>