Question

I'm showing 10 product my homepage but i need to partition 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?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top