我正在寻找一个函数,它可以为我提供画廊图像的缩略图,而不是完整图像。我目前使用$product->get_gallery_attachment_ids();
检索它们。
有问题的代码:
$attachment_ids = $product->get_gallery_attachment_ids();
$image_link = wp_get_attachment_url( $attachment_ids[0] );
echo "<img class='back-thumb' src='" . $image_link . "'></img>";
您可以使用专用的Wooccommercewc_get_gallery_image_html()
函数和WC_Product
方法get_gallery_image_ids()
,如:
if ( $attachment_ids = $product->get_gallery_image_ids() ) {
foreach ( $attachment_ids as $attachment_id ) {
echo wc_get_gallery_image_html( $attachment_id );
}
}
或类似于您的代码:
if ( $attachment_ids = $product->get_gallery_image_ids() )
echo wc_get_gallery_image_html( $attachment_ids[0] );
测试并工作。
更改缩略图尺寸和裁剪:请参阅本文档的部分