How to display Woocommerce Category image?

后端 未结 9 1509
说谎
说谎 2020-12-08 07:41

I use this code in PHP:

$idcat = 147;
$thumbnail_id = get_woocommerce_term_meta( $idcat, \'thumbnail_id\', true );
$image = wp_get_attachment_url( $thumbnail         


        
9条回答
  •  臣服心动
    2020-12-08 08:33

    To prevent full size category images slowing page down, you can use smaller images with wp_get_attachment_image_src():

    term_id, 'thumbnail_id', true );
    
    // get the medium-sized image url
    $image = wp_get_attachment_image_src( $thumbnail_id, 'medium' );
    
    // Output in img tag
    echo ''; 
    
    // Or as a background for a div
    echo '
    '; ?>

    EDIT: Fixed variable name and missing quote

提交回复
热议问题