我正在构建一个webshop,并开始在商店归档页面上配置产品循环。我会显示与每个产品相关的产品类别,并且我想设置这些类别,以获得我在管理页面上选择的背景。
我制作了一个ACF颜色选择器字段,并设置了颜色。
这是我的代码:
add_action( \'woocommerce_shop_loop_item_title\', \'VS_woo_loop_product_title\', 10 );
function VS_woo_loop_product_title() {
echo \'<h3>\' . get_the_title() . \'</h3>\';
$terms = get_the_terms( $post->ID, \'product_cat\' );
if ( $terms && ! is_wp_error( $terms ) ) :
//only displayed if the product has at least one category
$cat_links = array();
foreach ( $terms as $term ) {
$cat_links[] = $term->name;
}
$on_cat = join( " ", $cat_links );
?>
<div style="background: <?php the_field(\'kollekcio_szine\', $terms); ?>">
<?php echo $on_cat; ?>
</div>
<?php endif;
}
它根本不起作用。类别显示正确,但背景色不显示。如果我检查元素,我会看到background属性为空。我应该如何修改代码以使其正常工作?
谢谢你的帮助!