簡體   English   中英

magento最新產品清單

[英]magento latest product listing

我要在首頁顯示10個產品,但我需要對5,5分區。

我想要做

<div class="item active">1-5 Products</div>
<div class="item">5-10 Products</div>

當前代碼

<?php
$_helper = $this->helper('catalog/output');
$_productCollection = Mage::getResourceModel('reports/product_collection')
                ->addAttributeToSelect('*')
                ->setVisibility(array(2,3,4))                   
                ->setOrder('created_at', 'desc')
                ->setPageSize(10);
$count = $_productCollection->count();
?>

我該怎么做?

我認為您可以通過這種方式實現,但也可以嘗試簡單的解決方案

<?php
$_helper = $this->helper('catalog/output');
$_productCollection = Mage::getResourceModel('reports/product_collection')
                ->addAttributeToSelect('*')
                ->setVisibility(array(2,3,4))                   
                ->setOrder('created_at', 'desc')
                ->setPageSize(10);
$count = $_productCollection->count();
?>

    <div class="item active">
    <?php
        $i=0;
        $flag=false;
        foreach($_productCollection as $product)
        {
            if($i<5) 
            {  
            ?>
             <div class="lpitem">product <?php echo $i;?></div>
             <?php   $i++;
            ?>
            <?php 
            }
            else
            {
                if($i==5)
                {  
                    $flag=true;
                ?>
            </div>
            <div class="item">
                <?php 
            }?>
            <div class="lpitem">product <?php echo $i;?></div>
              <?php  $i++;
            ?>  
            <?php }
        }

    ?>
</div>    

讓我知道它是否對您有用

試試這個代碼:

$_helper = $this->helper('catalog/output');
$_productCollection = Mage::getResourceModel('reports/product_collection')
                ->addAttributeToSelect('*')
                ->setVisibility(array(2,3,4))                   
                ->setOrder('created_at', 'desc')
                ->setPageSize(10);
$count = $_productCollection->count();
<?php if($count):?>
<?php $i=0;foreach($_productCollection as $_product):?>
    <?php $product = Mage::getModel('catalog/product')->load($_product['entity_id']);?>
    <?php if($i%5==0): ?>
        <div class="item <?php if($i>5){?>active<?php }?>">
    <?php endif ?>
        echo $product->getName();
    <?php if($i%5==0): ?>
        </div>
    <?php endif ?>
<?php endforeach;?>
<?php endif;?>

它可能會幫助您。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM