最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

gallery - Add class to latest item Woocommerce

programmeradmin1浏览0评论

I need to woocommerce product gallery add class in latest item, if more than two pictures in the gallery do no need add the class to the last element, but if there are more than two images in the gallery - starting from three, need add the class to the last item, i have this code, code working and in latest item i can add class, but if less 3, dont know how:

<?php
              global $product;
                      $attachment_ids = $product->get_gallery_attachment_ids();
              $count = count($attachment_ids); $num = 0;
              foreach( $attachment_ids as $attachment_id ) {
                  $thumbnail_url = wp_get_attachment_image_src( $attachment_id, 'full' )[0];?>
              <li class="<?php if($num == $count-1){ ?><?php }else{ ?>small<?php }?>"><a class="product-images__list-item" href="<?php echo $thumbnail_url; ?>"><img src="<?php echo $thumbnail_url; ?>"></a></li>
              <?php $num++;?>
              <?php } ?>
发布评论

评论列表(0)

  1. 暂无评论