Magento: how do you change the number of product columns based upon page layout?
I know that in catalog.xml this line effects all layouts:
<action method="setColumnCount"><columns>5</columns></action>
But I want to change the number of columns based upon specific page layouts, i.e.: 2columns with left bar, 3 columns, etc.
This is what someone said to do but I am not sure I was adding the update tag in the right spot because it didn't seem to work. Also if you read the comments they say once you turn caching back on it breaks it: http://www.lotusseedsdesign.com/blog/change-grid-view-column-4-product-listing
So does anyone know how to use the addColumnCountLayoutDepend method or any other way to change the number of columns on the product grid specific to开发者_开发百科 the page layout?
For sub category page, in app/design/frontend/Your Interface/layout/catalog.xml change columns value the following line :
<action method="setColumnCount"><columns>4</columns></action>
For root category page, in app/design/frontend/Your Interface/template/catalog/product/list.phtml find the following code in "Grid Mode" section and change with appropiate value :
<?php $_columnCount = $this->getColumnCount(); ?>
like
<?php $_columnCount = 4; ?>
A bit old question (almost 3 years :D) but I found an interesting solution to this on Kathir 'Sid' Vel's site
For this you will edit catalog/product/list.phtml template.
Find the row:
<?php $_columnCount = $this->getColumnCount(); ?>
and replace with the code bellow or comment the line and add after it the code.
<?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 = 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;
}
?>
There are a few ways to change the column counts. You can try each method to see what suits you.
1) Watch this tutorial: http://www.youtube.com/watch?v=wNbV34v72a0 Here's the code you need to make it work.
<reference name="product_list">
<action method="setColumnCount"><count>4</count></action>
</reference>
2) If the above fails, use this in whatever CMS page you want to change the columns. So for example: if you have a CMS page for displaying a specific category, use this. This is especially great for displaying a specific category products and setting the number of items per row at the same time. Past the following code in your CMS page:
{{block type="catalog/product_list" category_id="42" template="catalog/product/showroom.phtml" columnCount="4"}}
You can change the columnCount number from 4 to whatever you want. You can get the category id by clicking on a category under your magento admin/category/manage category/
This is very important! Sometimes, when you do everything right in either of the two steps above, the items per row still does not change. The reason can easily be a CSS issue. So that leads to step 3:
3) Open your template's CSS and search for .products-grid Make sure the width is set to a number high enough to be able to display the number of items per row you want, without having to push down overflowing items. In my case, I tried all I could to have a 4 items per row but failed, until I noticed in the CSS that my .col1-layout .products-grid had a width of 750px. I changed the width to 995px and voila, step 2 worked flawlessly.
This is late but I hope it helps someone out there.
Go to app\design\frontend\base\default\layout\catalog.xml then go to Go to line 85 and fine the code. and find "catalog/product_list_toolbar" then customize the products according to your need.
Simplest way to change it is from the configuration tab
System->Configuration-> catalog tab-catalog->frontend you can change it easily from your magento backend.
精彩评论