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
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI 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
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;
?>
<?php
$galleryImages = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages();
$totalProductImgs = count($galleryImages);
$class = "img_"$totalProductImgs;
?>
$GalleryImages = Mage::getModel('catalog/product')->load($_product->getId())
->getMediaGalleryImages();
echo $totalImages = count($GalleryImages);