【问题标题】:Magento display multiple product images on details pageMagento 在详细信息页面上显示多个产品图像
【发布时间】:2019-08-14 13:04:43
【问题描述】:

我正在为每个产品上传 2 张图片。只有 2 个,不多不少。
第一张图片是产品基础图片,将显示在产品详细信息页面上。

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

$_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方式吗?

【问题讨论】:

    标签: magento


    【解决方案1】:
    <?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 并简单地提供数组的索引。

    【讨论】:

    • 我正在研究您的解决方案。我想我会用一些肮脏的伎俩让它发挥作用:)。并且为了记录,您不能在 view.phtml 页面上使用$this-&gt;getGalleryImages(),或者使用$images = $this-&gt;getGalleryImages(); $image2 = $images[1];,因为这里的数组索引是图像ID...
    • 谢谢@b00mer,我已经解决了我的问题。我使用 &lt;img src="&lt;?php echo $this-&gt;helper('catalog/image')-&gt;init($this-&gt;getProduct(), 'thumbnail', $_image-&gt;getFile())-&gt;resize(68,68); ?&gt;" alt="&lt;?php echo $this-&gt;htmlEscape($_image-&gt;getLabel()) ?&gt;" id="&lt;?php echo 'image-'.$ctr ?&gt;" style="display:none"/&gt; 打印所有图像并使用 jQuery 显示图像
    • 在您的回答中,$this 是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 2013-10-16
    相关资源
    最近更新 更多