我們目前正在對Magento的主頁使用裝載產品的媒體庫圖片如下: -只得到最大的3個媒體畫廊圖像getMediaGalleryImages在Magento
<?php $_images = Mage::getModel('catalog/product')->load($product->getId())->getMediaGalleryImages(); ?>
<?php if($_images){?>
<?php $i=0; foreach($_images as $_image){ $i++; ?>
<img class="gallery" src="<?php echo $this->helper('catalog/image')->init($product, 'thumbnail', $_image->getFile())->resize(255); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel());?>" title="<?php $this->htmlEscape($_image->getLabel());?>" />
<?php } ?>
<?php } ?>
目前這將得到所有產品的媒體畫廊圖像,但我們只希望得到最多3.請有人建議如何可以重寫以上只能得到3?
我不能確定,如果突破foreach
循環就是這一點,因此我有發揮各地的最佳方法: -
<?php if (++$i == 3) break; ?>
但是,這似乎並沒有一致的最多隻有返回的3.
在此先感謝。