小编spa*_*abs的帖子

获取 Woocommerce 产品类别图片网址

我使用以下代码来获取 Woocommerce 产品类别的缩略图 URL,但它只输出<img>带有src="unknown".

$cat_slug = t-shirts;
$thumbnail_id = get_woocommerce_term_meta( $cat_slug, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
echo '<img src="'.$image.'" alt="" width="50" height="50" />'; 
Run Code Online (Sandbox Code Playgroud)

让它发挥作用的最佳方法是什么?

编辑

在第二次调用 jean 类别的缩略图时,它只输出<img src(unknown) alt="" width="50" height="50" />.

<div class="list-item">
    <div class="item-img">

        <?php

        $term_slug    = 't-shirts';
        $taxonomy     = "product_cat";
        $term_id      = get_term_by( 'slug', $term_slug, $taxonomy )->term_id;
        $thumbnail_id = get_woocommerce_term_meta( $term_id, 'thumbnail_id', true );
        $image        = wp_get_attachment_url( $thumbnail_id );

        echo '<img src="'.$image.'" alt="" width="50" height="50" />';

        ?> …
Run Code Online (Sandbox Code Playgroud)

php wordpress image custom-taxonomy woocommerce

2
推荐指数
1
解决办法
8625
查看次数

如何在父项悬停时更改子元素的不透明度

我希望在父div悬停时更改子div图像的不透明度.如何在CSS中执行此操作?

<div class="parent">
    <div class="child">
        <img src="" alt="" height="" width="">
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

html css

0
推荐指数
1
解决办法
119
查看次数

标签 统计

css ×1

custom-taxonomy ×1

html ×1

image ×1

php ×1

woocommerce ×1

wordpress ×1