盛龙科技

woocommerce调用产品相册gallery图片如何操作

ordpress官网有很多woocommerce模板,但有些客户要求定制模板,这时可能会碰到产品相册图片调用的问题,如果根据自带的Storefront主题来改很麻烦,那我们就自己定义吧!一起来看看woocommerce调用产品相册gallery图片吧!

<?php
  global $product;
 $attachment_ids = $product->get_gallery_attachment_ids();
 
foreach( $attachment_ids as $attachment_id )
{
  //Get URL of Gallery Images - default wordpress image sizes
  echo $Original_image_url = wp_get_attachment_url( $attachment_id );
  echo $full_url = wp_get_attachment_image_src( $attachment_id, 'full' )[0];
  echo $medium_url = wp_get_attachment_image_src( $attachment_id, 'medium' )[0];
  echo $thumbnail_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail' )[0];
   
  //Get URL of Gallery Images - WooCommerce specific image sizes
  echo $shop_thumbnail_image_url = wp_get_attachment_image_src( $attachment_id, 'shop_thumbnail' )[0];
  echo $shop_catalog_image_url = wp_get_attachment_image_src( $attachment_id, 'shop_catalog' )[0];
  echo $shop_single_image_url = wp_get_attachment_image_src( $attachment_id, 'shop_single' )[0];
   
  //echo Image instead of URL
  echo wp_get_attachment_image($attachment_id, 'full');
  echo wp_get_attachment_image($attachment_id, 'medium');
  echo wp_get_attachment_image($attachment_id, 'thumbnail');
  echo wp_get_attachment_image($attachment_id, 'shop_thumbnail');
  echo wp_get_attachment_image($attachment_id, 'shop_catalog');
  echo wp_get_attachment_image($attachment_id, 'shop_single');
}
?>

具体的代码如下(一个是调用产品特色图the_post_thumbnail_url,一个是产品相册gallery图片)

<!-- Swiper -->
                <div class="swiper-container gallery-top">
                    <div class="swiper-wrapper">
                        <div class="swiper-slide">
                            <img src="<?php the_post_thumbnail_url( 'full' ); ?>" alt="">
                        </div>
                            <?php
                            global $product;
                            $attachment_ids = $product->get_gallery_attachment_ids();
                            foreach( $attachment_ids as $attachment_id )
                            {
                                echo '<div class="swiper-slide"><img src="' .$full_url = wp_get_attachment_image_src( $attachment_id, 'full' )[0] .'" alt=""></div>';
                            }
                            ?>
                    </div>
                    <!-- Add Arrows -->
                    <div class="swiper-button-next hidden-xs"></div>
                    <div class="swiper-button-prev hidden-xs"></div>
                </div>
                <div class="swiper-container gallery-thumbs">
                    <div class="swiper-wrapper">
                        <div class="swiper-slide">
                            <img src="<?php the_post_thumbnail_url( 'small' ); ?>" alt="">
                        </div>
                        <?php
                        global $product;
                        $attachment_ids = $product->get_gallery_attachment_ids();
                        foreach( $attachment_ids as $attachment_id )
                        {
                            echo '<div class="swiper-slide"><img src="' .$shop_thumbnail_image_url = wp_get_attachment_image_src( $attachment_id, 'shop_thumbnail' )[0] .'" alt=""></div>';
                        }
                        ?>
                    </div>
                </div>

当然,js和css文件需要自己定义

<div class="swiper-slide">
    <img src="<?php the_post_thumbnail_url( 'full' ); ?>" alt="<?php the_title(); ?>">
</div>
<?php
global $product;
$attachment_ids = $product->get_gallery_attachment_ids();
 
foreach( $attachment_ids as $attachment_id )
{
    echo '<div class="swiper-slide"><img src="' .$full_url = wp_get_attachment_image_src( $attachment_id, 'full' )[0] .'" alt="';
    the_title();
    echo '"></div>';
}
?>
woocommerce
本文由 8源码吧 作者:liaolong 发表,其版权均为 8源码吧 所有,文章内容系作者个人观点,不代表 8源码吧 对观点赞同或支持。如需转载,请注明文章来源。
分享: 
  
Q1 免费下载或者VIP会员资源能否直接商用?
本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
Q2 提示下载完但解压或打开不了?
最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。 若排除这种情况,可在对应资源底部留言,或联络我们。
Q3 找不到素材资源介绍文章里的示例图片?
对于会员专享、整站源码、程序插件、网站模板、网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。
Q4 付款后无法显示下载地址或者无法查看内容?
如果您已经成功付款但是网站没有弹出成功提示,请联系站长提供付款信息为您处理
Q5 购买该资源后,可以退款吗?
源码素材属于虚拟商品,具有可复制性,可传播性,一旦授予,不接受任何形式的退款、换货要求。请您在购买获取之前确认好 是您所需要的资源

评论交流(0)

发表评论

相关推荐