2014-09-26 219 views
0

開發人員在我的magento網站上創建了一個自定義模塊,該模塊列出了網頁上每個類別中最便宜的產品。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 &gt;&gt;</div> 
        <div class="name"><?php echo strtoupper($curr->getName()); ?></div> 

       </a> 
      </div> 
      <? 
     }   
    } 
} 
?> 
<br class="clear"/> 
</div> 

我試圖切片數組,但顯然這不是一個正常的數組。也試圖使用循環,而不是foreach沒有給我帶來積極的結果。

你有什麼想法來解決這個問題嗎?先謝謝你。

回答

0

只需計算您的foreach循環中的行數,並在達到所需數量時退出或繼續?