doiftrue / wp_term_image
为WordPress分类术语上传图片功能。在管理面板中。
v3.5.2
2022-07-30 08:48 UTC
Requires
- php: >=5.6.0
README
添加为WordPress术语(分类元素)设置缩略图的功能,包括内置(标签、类别)和自定义的。
更多信息请点击此链接: https://wp-kama.ru/7686
使用示例
连接
包含 WP_Term_Image.php
php 文件
require_once __DIR__ . '/WP_Term_Image.php';
或使用Composer
composer require doiftrue/wp_term_image
初始化
不带参数的基本设置
add_action( 'admin_init', [ \Kama\WP_Term_Image::class, 'init' ] );
带参数的设置
add_action( 'admin_init', 'kama_wp_term_image' ); function kama_wp_term_image(){ // Let's specify for which taxonomy it is necessary to set images. // It is possible not to specify, then the possibility will be automatically added for all public taxonomies. \Kama\WP_Term_Image::init( [ 'taxonomies' => [ 'post_tag' ], ] ); }
在主题模板中获取数据
获取术语附件图像ID的示例
$image_id = \Kama\WP_Term_Image::get_image_id( $term_id ); // OR $image_id = get_term_meta( $term_id, '_thumbnail_id', 1 );
现在我们可以使用ID来获取附件的URL
$image_url = wp_get_attachment_image_url( $image_id, 'thumbnail' );