0

目前我正在使用来自 MagePsycho jquery 灯箱的扩展。此扩展程序在前端调用所有缩略图并显示为“更多视图”缩略图,我想限制它们。media.phtml 中的代码是:

`<div class="more-views">
<h2><?php echo $helper->getConfig('more_views_label') ?></h2>
<ul>
<?php foreach ($this->getGalleryImages() as $_image):
        if(empty($popUpImageSize[0]) || empty($popUpImageSize[0])):
            $popUpImage = $this->helper('catalog/image')->init($this->getProduct(),           'image', $_image->getFile());
        else:
            $popUpImage = $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())->resize($popUpImageSize[0], $popUpImageSize[1]);
        endif;
?>
    <li>
        <a href="<?php echo $popUpImage; ?>" rel="<?php echo $rel; ?>" class="<?php echo  $class; ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize($thumbnailSize[0], $thumbnailSize[1]); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
    </li>
<?php endforeach; ?>
</ul>

`

并附上描述问题的图像。谢谢在此处输入图像描述

4

1 回答 1

1

看起来您已经拥有所需的所有信息。

你有一个循环遍历每个图像

<?php foreach ($this->getGalleryImages() as $_image):
    //output thumbnail code snipped
<?php endforeach; ?>

而不是循环每个项目,您只想循环四次。有很多不同的方法可以实现这一目标。这是使用哨兵值的一个

<?php $c = 0; ?> //define a counter
<?php foreach ($this->getGalleryImages() as $_image):
    //output thumbnail code snipped
    <?php if($c > 3) { break; } ?> //break if we've looped four times 
    <?php $c++?>                   //increment the counter
<?php endforeach; ?>
于 2013-03-23T04:35:58.450 回答