我每个产品上传大约30张图片,其数字名称如下:
001.png 002.png 003.png ....
但上传后显示在前端,如
002.png 003.png 001.png ....
怎么可能在前端自动排序以下是来自Magento media.phtml的代码
<ul class="product-image-thumbs">
<?php foreach ($this->getGalleryImages() as $_image):?>
<li>
<a href="<?php echo Mage::helper('catalog/image')->init($_product, 'image', $_image->getFile()); ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" rel="prettyPhoto[mixed]">
<img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize($_thumbWidth, $_thumbHeight); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" />
</a>
</li>
<?php endforeach?>
<?php if ($_360IsSet && !$_embedded):?>
<?php $_360ViewWidth = preg_replace("/[^0-9]/", "", $_360ViewWidth) ?>
<?php $_360ViewHeight = preg_replace("/[^0-9]/", "", $_360ViewHeight) ?>
<li>
<a href="<?php echo $this->getSkinUrl('webrotate360/frame_' . $_viewerSkin . '.html') . '?iframe=true&width=' . $_360ViewWidth . '&height=' . $_360ViewHeight ?>" rel="prettyPhoto[mixed]">
<img src="<?php echo $_360icon ?>" />
</a>
</li>
<?php endif?>
</ul>
答案 0 :(得分:0)
肯定@WhiteHat这是我的代码:
var mediaImages = [<?php $numItems = count($this->getGalleryImages());$i = 0;foreach ($this->getGalleryImages() as $_image):?> <?php echo '"'?><?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(450, 450); if(++$i === $numItems) { echo '"';} else { echo '",';}?><?php endforeach?>];
var mediaImagesSorted = mediaImages.sort();
jQuery('.MediaDiv').html(mediaImagesSorted);