Magento在详细信息页面上显示多个产品图像

时间:2011-11-01 13:33:11

标签: magento

我正在为每种产品上传2张图片。只有2不多也不少。
Product Images http://i43.tinypic.com/2py6zpu.png 第一张图片是产品基本图片,将显示在产品详细信息页面上。

我正在使用以下行显示此图片:

$_img = '<img src="'.$this->helper('catalog/image')->init($_product, 'image')->resize(180, 300).'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />';
                echo $_helper->productAttribute($_product, $_img, 'image');

我能够正确显示上面的图像。

单击特定链接时,将弹出第二个图像。我不想展示一个画廊。只想分别显示每个图像。

我想我找到了一种方法来检索上传的图像数组:

$productData = $_product->getData();
$secondImage = $productData['media_gallery']['images'][1];

现在,我不确定如何显示此图像。我的意思是如何使用帮助器,就像我用于第一个图像制作显示第二个图像。 我可以选择硬编码完整的图像路径并使用:

$secondImage['file']; 

显示图像等,但是,我想知道是否有办法,我可以用magento方式做到吗?

1 个答案:

答案 0 :(得分:2)

<?php foreach ($this->getGalleryImages() as $_image): ?>
  <li>
     <a href="#" onclick="popWin('<?php echo $this->getGalleryUrl($_image) ?>', 'gallery', 'scrollbars=yes,width=200,height=200,resizable=yes');return false;">
     <img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(68,68); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>"/>
     </a>
  </li>
<?php endforeach; ?>

代码取消:

http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/catalog/adding_lightbox_to_magento_v2

请注意答案,但显然你可以删除foreach并只提供数组的索引,如果你知道你只有一个文件。

相关问题