简体   繁体   English

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

[英]Magento: Get Image Gallery in list.phtml

How can I grab the image gallery into the category page in Magento, for a loaded product? 如何将图库转移到Magento的类别页面中,以获取已加载的产品?

this->getImageGallery($_product)

, won't work.. ,不会工作..

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

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

If I add the images to a product programmatically then $product->getMediaGalleryImages() has zero images... however 如果我以编程方式将图像添加到产品中,那么$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']);
}

works fine 工作良好

Here's another method which doesn't require loading the entire product object. 这是另一种不需要加载整个产品对象的方法。

<?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; ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM