Magento Forum

Second row of products generated inside the first one, how can I fix this? 
 
iXtremiXpert
Jr. Member
 
Avatar
Total Posts:  29
Joined:  2012-04-18
 

The following code is supposed to show featured products and it worked great with one row of 5 products.

<?php if (($_products $this->getProductCollection()) && $_products->getSize()): ?>
    
<div class="category-products childcatlist">

        
<?php $i=0;$row=0; foreach ($_products->getItems() as $_product): ?>

            <?php 
if($i==0):?>
                <?php $row
++;?>
                
<ul class="products-grid grid-wide spec-grid spec-grid3col clearer <?php echo (($row%2)>0) ? 'odd' : 'even' ?>">
                
            
<?php endif;?>
                    
<li class="item">
                        <
div class="title-over-image"><h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h2></div>
                        <
a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(TRUE)->keepAspectRatio(FALSE)->keepFrame(FALSE)->adaptiveResize(176, 176)
//height is the same is width; ?>" 
alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /><?php // Code displaying product labels "new" and "sale". It's a copy of 'catalog/product/view/media_labels.phtml'
                        
require('view/media_labels.inc.phtml'); ?></a>
                        
                        
                    </
li>

            
<?php $i++; if($i==$this->getItemsPerRow()):?>
                <?php $i
=0;?>
                
            <?php 
endif;?>
        <?php 
endforeach; ?>

    
</ul>
    </
div>
<?php endif; ?>

Now I want to place more products and I realized the second row is generated INSIDE the first one, as seen in the attached screenshot.

How can I edit the code so that the second row won’t be generated INSIDE the first one?

Image Attachments
problem.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
iXtremiXpert
Jr. Member
 
Avatar
Total Posts:  29
Joined:  2012-04-18
 

Anyone has any idea on how I can fix this problem?

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagenX
Enthusiast
 
Total Posts:  791
Joined:  2008-05-26
Dublin
 

i think you have to keep your last </ul> element inside your if

<?php $i++; if($i==$this->getItemsPerRow()):?>
                <?php $i
=0;?>
                
</ul
            
<?php endif;?>
        <?php 
endforeach; ?>

not sure what you mean anyway

 
Magento Community Magento Community
Magento Community
Magento Community
 
iXtremiXpert
Jr. Member
 
Avatar
Total Posts:  29
Joined:  2012-04-18
 

Thank you MagenX, your solution works great.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top