Magento产品列表显示,默认是每行3个产品。如何更改这个值呢?

我曾看到过一篇文章,它是通过修改template/catalog/product/list.phtml模板文件来实现的。其实没这样复杂,Magento早就为我们提供了一个机关,就暗藏在layout(布局)xml文件中。

一、设置产品列表,一行显示4个产品。修改模板的layout/catalog.xml文件:

<REFERENCE name=”content”>
   <BLOCK name=”category.products” template=”catalog/category/view.phtml” type=”catalog/category_view”>
      <BLOCK name=”product_list” template=”catalog/product/list.phtml” type=”catalog/product_list”>
         <!– 增加下面这行指令 –>
         <ACTION method=”setColumnCount”><COUNT>4</COUNT></ACTION>>

注意,上面的机关:

<ACTION method=”setColumnCount”><COUNT>4</COUNT></ACTION>
虽然类别页面中的产品类别已经设置了,但不要忘了,还有个搜索结果页面,也需要进行同样的设置。

二、设置搜索结果页面中,一行显示的产品个数,这个要到模板的layout/catalogsearch.xml中来修改:

<REFERENCE name=”content”>
   <BLOCK name=”search.result” template=”catalogsearch/result.phtml” type=”catalogsearch/result”>
      <BLOCK name=”search_result_list” template=”catalog/product/list.phtml” type=”catalog/product_list”>
         <!– 增加下面这行指令 –>
         <ACTION method=”setColumnCount”><COLUMNS>4</COLUMNS></ACTION>

细心的你,可能已经注意到了,这里的是:
<COLUMNS>4</COLUMNS>
而不是先前的:
<COUNT>4</COUNT>

我测试过了,你即使改成:
<shuimu>4</shuimu>
也是可以的:)