Magento:按字母顺序对产品显示图像进行排序
Magento: Sort product display images in alphabetical order
我正在为每个产品上传大约 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>
确定@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);
我正在为每个产品上传大约 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>
确定@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);