Categories
Magento

Magento – Easy Method to Set the Number of Columns in Product List.phtml Without XML

[php]
<?php

/* Edit the catalog/product/list.phtml template to include the following */

/* 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 = 4;
break;

case ‘page/2columns-left.phtml’:
$_columnCount = 3;
break;

case ‘page/2columns-right.phtml’:
$_columnCount = 3;
break;

case ‘page/3columns.phtml’:
$_columnCount = 2;
break;

default:
$_columnCount = 3;
break;
}

/* Comment out or remove the Magento Column Count function usage */
/* $_columnCount = $this->getColumnCount(); */

?>
[/php]

6 replies on “Magento – Easy Method to Set the Number of Columns in Product List.phtml Without XML”

Thanks Kathir Vel,

This is very useful code who is new in Magento as a theme designer also don’t know php coding. My problem has been resolved. great..

I cannot, for the life of me, get these _columnCount changes to work. I’ve tried via catalog.xml, and list.phtml, and nothing seems to work. I’m running 1.8. Any thoughts on what might be causing this to not update?

Hard coding the columncount should work. The column count is used in the same list.phtml file during the loop. Can you check if you can see the usage of $_columnCount?

Comments are closed.