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

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

?>