We've extended a homepage slider for a client so that they can feature products in this space.
As part of this, there are three image slots where we wish to get the products' main image and then two images from the media gallery (ideally randomly but not the end of the world if by ID).
To get a better understanding, please see screenshot of what we have so far:-
We're building the collection for this module using the following:-
$featured_products = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect('*') ->AddAttributeToFilter('featured', array('eq' => 1));
Getting the product's main image is no problem, this is working perfectly with the following:-
<img class="gallery" src="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(225); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($product, 'small_image'), null, true) ?>" />
And it is simple enough to make all three image slots use this main image as shown in the image above.
When we try to call getGalleryImages however, this always returns
NULL (example such as):-
<?php if (count($this->getGalleryImages()) > 0): ?> <?php foreach ($this->getGalleryImages() as $_image): ?> <img class="gallery" src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(100); ?>" width="100" height="100" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /> <?php endforeach; ?> <?php endif; ?>
Please could someone advise of the best approach to call the gallery images on the homepage. Is there something we can include to the collection build or would we need to add an observer.
Thanks in advance.