Search code examples
magento

How to have different amount of products per row, different in each page layout


https://magento.stackexchange.com/questions/12899/display-more-items-per-row-in-products-page

^ This post is a guide to set 4 products per row | For all pages.

I want to set a different amount of products for each page layout.

THE GOAL:

  • 3 Products per row for 3 Column-Page Layout
  • 4 Products per row for 2 Column ^
  • 5 Products per row for 1 Column ^

Please give instructions to customize products per row.


Solution

  • In app/design/frontend/yourtheme/default/template/catalog/product/list.phtml (create it if you haven't by copying from app/design/frontend/base/default/template/catalog/product/list.phtml) and replace the line:

    <?php // Grid Mode ?>
    
    <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
    

    with

    <?php $_collectionSize = $_productCollection->count() ?>
    
    <?php
    
    // Get the layout's page template
    $pageLayoutRootTemplate = $this->getLayout()->getBlock('root')->getTemplate();
    // Set the column count based on the layout template used
    switch ($pageLayoutRootTemplate) {
        case 'page/1column.phtml':
            $_columnCount = 5;
            break;
        case 'page/2columns-left.phtml':
            $_columnCount = 4;
            break;
        case 'page/2columns-right.phtml':
            $_columnCount = 4;
            break;
        case 'page/3columns.phtml':
            $_columnCount = 3;
            break;
        default:
            $_columnCount = 3;
            break;
    }
    // comment normal line out $_columnCount = $this->getColumnCount(); ?>
    
    <?php $i=0; foreach ($_productCollection as $_product): ?>
    

    Obviously modify it to what you want.