I need to get a comma separated list of image URL's from a product's media gallery.

I have successfully managed to load getMediaGalleryImages so that if I...

var_dump ($product->getMediaGalleryImages());

... I can see each image being loaded with it's attributes, i.e:-

["url"]=> string(89) "https://www.example.com/media/catalog/product/x/x/x-image.jpg"

I just haven't managed to figure out how to list them in an array like:-

https://www.example.com/media/catalog/product/x/x/x-image.jpg, https://www.example.com/media/catalog/product/x/x/x-image_1.jpg, https://www.example.com/media/catalog/product/x/x/x-image_2.jpg

Struggling to get the syntax right I think...


I figured this out earlier so here is how I displayed a comma separated list of image URL's from getMediaGalleryImages...

$gallery_images = Mage::getModel('catalog/product')->load($product->getId())->getMediaGalleryImages();

$items = array()

foreach($gallery_images as $g_image) {
    $items[] = $g_image['url'];

Then I could output with:-

implode(', ', $items);
  • 2
    Avoid loading the entire object, it's better to add the gallery images to your collection. Dec 9 '16 at 15:09

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.