2011-11-01 134 views
2

我爲每個產品上傳2張圖像。只有2個不多,不少。
Product Images http://i43.tinypic.com/2py6zpu.png 1st image is product base image and will be displayed on product details page。Magento在詳細信息頁面上顯示多個產品圖像

我使用下面的行顯示這些圖像:

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

回答

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,只需提供數組的索引,如果你知道你只會有一個文件。

+0

我正在處理您的解決方案。我想我會有一些骯髒的伎倆,使其工作:)。並且爲了記錄,您不能在** view.phtml **頁面上使用'$ this-> getGalleryImages()',或者執行'$ images = $ this-> getGalleryImages(); $ image2 = $ images [1];'因爲,這裏的數組索引是圖像ID ... – Ravish

+0

謝謝@ b00mer,我解決了我的問題。我使用' Ravish

+0

無法在1.9中顯示任何圖像 –

相關問題