在循环中显示产品库中的第二张 WooCommerce 图像

我正在使用此代码来显示 woocommerce 拇指:


    <?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; ?>">

但寻找解决方案如何显示产品库中的第二张图像。如何修改这段代码呢?


泛舟湖上清波郎朗
浏览 111回答 1
1回答

函数式编程

更新:以下将显示产品库中的第二张图片(第一张图片):<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $loop->post->ID ), 'single-post-thumbnail' ); ?><img src="<?php&nbsp; echo $image[0]; ?>" data-id="<?php echo $loop->post->ID; ?>"><?php// Get gallery images IDsif( $gallery_image_ids = get_post_meta( $loop->post->ID, '_product_image_gallery', true ) ) :&nbsp; &nbsp; // Convert a coma separated string of Ids to an array of Ids&nbsp; &nbsp; $gallery_image_ids = explode(',', $gallery_image_ids);&nbsp; &nbsp; // Display the first image (optional)&nbsp; &nbsp; ?><img src="<?php echo wp_get_attachment_image_url( reset($gallery_image_ids), 'single-post-thumbnail'); ?>" data-id="<?php echo $loop->post->ID; ?>">&nbsp; &nbsp; <?php&nbsp; &nbsp; // Display the 2nd image (if it exists)&nbsp; &nbsp; if( isset( $gallery_image_ids[1] ) ) :&nbsp; &nbsp; &nbsp; &nbsp; ?><img src="<?php echo wp_get_attachment_image_url( $gallery_image_ids[1], 'single-post-thumbnail'); ?>" data-id="<?php echo $loop->post->ID; ?>">&nbsp; &nbsp; <?php endif; ?><?php endif; ?>
打开App,查看更多内容
随时随地看视频慕课网APP