2

I want to add HTML class in view.phtml as per product images.

Like: If product have one image then class add img_1. if have two then img_2

How to get number of images count in view.phtml

2

Try this code.

<?php 
    $GalleryImages = Mage::getModel('catalog/product')->load($_product->getId())
                    ->getMediaGalleryImages();

    $count_img = 1;

     if(count($GalleryImages)) {
       foreach($GalleryImages as $simplemediagalleryimage) {
        $count_img++;
         }
     }
echo "img_".$count_img;
 ?>
  • The gallery images are usually output by view/media.phtml, not view.phtml, and the rwd media.phtml template already assigns each image an id of the format image-$i – Richard Jul 26 '16 at 9:19
2
<?php 
    $galleryImages = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages();

    $totalProductImgs = count($galleryImages);

    $class = "img_"$totalProductImgs;
 ?>
1
 $GalleryImages = Mage::getModel('catalog/product')->load($_product->getId())
                  ->getMediaGalleryImages();

 echo  $totalImages = count($GalleryImages);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.