magento最新产品上市

时间:2014-03-28 08:30:39

标签: list magento product

我在我的主页上显示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();
?>

我该怎么做?

2 个答案:

答案 0 :(得分:1)

我认为您可以通过这种方式实现,但您也可以尝试轻松解决方案

<?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>    

让我知道它是否适合您

答案 1 :(得分:0)

试试这段代码:

$_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;?>

它可能对你有帮助。