我有使用types插件创建的自定义帖子类型和类别。
我使用Categories images插件允许/创建类别图像。
我有一个循环,显示中某个类别的帖子<li>
s
每个<li>
具有需要获取指定给该类别的图像的背景样式属性。
这是我的适用代码:
$film_categories = get_terms( \'category\' );
foreach ( $film_categories as $film_category ) {
$film_category_query = new WP_Query( array(
\'post_type\' => \'film\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'category\',
\'field\' => \'slug\',
\'terms\' => array( $film_category->slug ),
\'operator\' => \'IN\'
)
)
));
$term_id = get_terms(\'category\');
if ( $film_category_query->have_posts() ) : while ( $film_category_query->have_posts() ) : $film_category_query->the_post();
//$film_background_image = apply_filters( \'taxonomy-images-queried-term-image-url\', \'\' );
//$film_background_color = types_render_field("film-background-color");
$hide_all_info = types_render_field("hide-all-info");
$film_image = types_render_field("film-image");
$film_meta_info = types_render_field("film-meta");
?>
<?php var_dump($term_id); ?>
<li id="<?php echo $film_category->{\'slug\'}; ?>" style="background: url(<?php echo z_taxonomy_image_url($term_id); ?>); background-size: cover;">
当我
var_dump($term_id)
我明白了:
array(2){
[0]=> object(stdClass)#380 (9)
{ ["term_id"]=> string(1) "3" ["name"]=> string(10) "Commercial" ["slug"]=> string(10) "commercial" ["term_group"]=> string(1) "0" ["term_taxonomy_id"]=> string(1) "3" ["taxonomy"]=> string(8) "category" ["description"]=> string(0) "" ["parent"]=> string(1) "0" ["count"]=> string(1) "1" }
[3]=> object(stdClass)#377 (9)
{ ["term_id"]=> string(1) "5" ["name"]=> string(4) "Reel" ["slug"]=> string(4) "reel" ["term_group"]=> string(1) "0" ["term_taxonomy_id"]=> string(1) "5" ["taxonomy"]=> string(8) "category" ["description"]=> string(0) "" ["parent"]=> string(1) "0" ["count"]=> string(1) "1" }
}
如何获取每个类别的id,以便
z_taxonomy_image_url
函数可以使用它来检索类别图像url吗?