1 回答
TA贡献1807条经验 获得超9个赞
更新:以下将显示产品库中的第二张图片(第一张图片):
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $loop->post->ID ), 'single-post-thumbnail' ); ?>
<img src="<?php echo $image[0]; ?>" data-id="<?php echo $loop->post->ID; ?>">
<?php
// Get gallery images IDs
if( $gallery_image_ids = get_post_meta( $loop->post->ID, '_product_image_gallery', true ) ) :
// Convert a coma separated string of Ids to an array of Ids
$gallery_image_ids = explode(',', $gallery_image_ids);
// Display the first image (optional)
?><img src="<?php echo wp_get_attachment_image_url( reset($gallery_image_ids), 'single-post-thumbnail'); ?>" data-id="<?php echo $loop->post->ID; ?>">
<?php
// Display the 2nd image (if it exists)
if( isset( $gallery_image_ids[1] ) ) :
?><img src="<?php echo wp_get_attachment_image_url( $gallery_image_ids[1], 'single-post-thumbnail'); ?>" data-id="<?php echo $loop->post->ID; ?>">
<?php endif; ?>
<?php endif; ?>
- 1 回答
- 0 关注
- 105 浏览
添加回答
举报