Magento:在list.phtml中获取图片库

时间:2010-09-20 22:52:30

标签: magento

如何将图片库放入Magento的类别页面中,以获取已加载的产品?

this->getImageGallery($_product)

,无法正常工作..

3 个答案:

答案 0 :(得分:18)

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

foreach ($product->getMediaGalleryImages() as $image) {
    echo var_export($image->getUrl());
} 

答案 1 :(得分:4)

如果我以编程方式将图片添加到产品中,那么$product->getMediaGalleryImages()图像......但是

$mediaApi = Mage::getModel('catalog/product_attribute_media_api');
$mediaItems = $mediaApi->items($product->getId());
foreach ($mediaItems as $image) {
  error_log('found url: '.$image['file']);
}

工作正常

答案 2 :(得分:0)

这是另一种不需要加载整个产品对象的方法。

<?php $media_gallery = $_product->getMediaGallery(); ?>
<?php foreach ($media_gallery['images'] as $_image):?>
    <img src="<?php echo $this->helper('catalog/image')->init($_product, 'image', $_image['file'])->resize(135); ?>" alt="<?php echo $this->escapeHtml($_image['label']) ?>" />
<?php endforeach; ?>