[英]Magento product listing
开发人员在我的magento网站上创建了一个自定义模块,该模块列出了页面上每个类别中价格最低的产品。
很棒,但是现在页面太长了,无法添加其他内容。 如何将显示的类别数限制为10个,甚至更好-可以指定顺序的10个类别?
换句话说,我想以相同的方式显示所有内容,但将类别数限制为10,并使用类别ID指定它们的顺序。
这是原始代码:
$helper = Mage::helper('catalog/category');
$helperOutput = Mage::helper('catalog/output');
$categories = $helper->getStoreCategories('name', true, true);
?>
<div class="specials_list">
<?
// Iterate all categories in store
foreach ($categories as $curr){
// If category is Active
if($curr->getIsActive()){
$info = Mage::getModel('catalog/category')->load($curr->getId());
$product = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($info)->addAttributeToSelect('small_image');
$product->addMinimalPrice();
$product->getSelect()->order("price", "ASC")->limit(1);
$product->load();
foreach($product as $temp){}
$product = $temp;
if($product){
?>
<div class="product">
<a href="<?php echo $helper->getCategoryUrl($curr)?>">
<img src="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(135, 135); ?>" width="135" alt="<?php echo $product->getName() ?>" />
<div class="price">From <span class="amount"><? echo Mage::helper('core')->currency($product->getPrice(),true,false); ?></span></div>
<div class="view">View All >></div>
<div class="name"><?php echo strtoupper($curr->getName()); ?></div>
</a>
</div>
<?
}
}
}
?>
<br class="clear"/>
</div>
我试图对数组进行切片,但显然它不是普通数组。 尝试使用for循环代替foreach也没有给我任何积极的结果。
您是否对解决此问题有任何想法? 先感谢您。
只需计算您的foreach循环中的行数,然后在达到所需数量时退出还是继续?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.