kunoichi / term-meta
一个用于轻松处理术语元数据的实用工具。
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>