简体   繁体   English

magento最新产品清单

[英]magento latest product listing

I'm showing 10 product my homepage but i need to partition 5,5. 我要在首页显示10个产品,但我需要对5,5分区。

I want to do 我想要做

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

Current Codes 当前代码

<?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();
?>

How do I make this? 我该怎么做?

I think you can achieve in this way but you can also try easy solution 我认为您可以通过这种方式实现,但也可以尝试简单的解决方案

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

Let me know if its works for you or not 让我知道它是否对您有用

Try this code: 试试这个代码:

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

It may help you. 它可能会帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM