0
我試圖在woocommerce的單個產品頁面上獲取與產品相關的所有圖像的尺寸(大小)。 我需要photoswipes「data-size」值的值寬度和高度。woocommerce獲取圖像大小
這就是我現在
<ul class="slides">
<?php
$attachment_ids = $product->get_gallery_attachment_ids();
$attachment_first[0] = get_post_thumbnail_id($product->id);
$attachment = wp_get_attachment_image_src($attachment_first[0], 'full');
$img_size = wc_get_image_size($attachment_ids, 'full');
$w = $img_size['width'];
$h = $img_size['height'];
$size = $w .'x'. $h;
?>
<li class="picture">
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="<?php echo $attachment[0]; ?>" itemprop="contentUrl" data-size="<?php echo $size; ?>">
<img src="<?php echo $attachment[0]; ?>" itemprop="image" />
<?php echo $size; ?>
</a>
</figure>
</li>
<?php
foreach($attachment_ids as $attachment_id){
$src_url = wp_get_attachment_url($attachment_id);
echo '<li class="picture"><figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject"><a href="' . $src_url . '" itemprop="contentUrl" data-size="' . $size . '"><img src="' . $src_url . '" itemprop="image" />'.$size .'</a></figure></li>';
}
?>
</ul>
它正確地得到所有的圖像,但寬度和高度值是關閉。我知道我正在測試的產品的完整圖像是800x800。如果我在
wc_get_image_size($attachment_ids, 'full');
刪除 「$ attachment_ids」 那麼值變爲300×300。
我真的需要找到一個簡單的方法來從woocommerce得到實際尺寸的全尺寸圖像。 我還以爲這個任務本來簡單:P