admin管理员组

文章数量:1023803

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 } ?>

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 } ?>

本文标签: galleryAdd class to latest item Woocommerce