Magento:如何根据页面布局更改产品列的数量?

发布于 2024-10-19 15:46:52 字数 519 浏览 3 评论 0原文

我知道在catalog.xml中这一行会影响所有布局:

   <action method="setColumnCount"><columns>5</columns></action> 

但我想根据特定的页面布局更改列数,即:2列带左栏,3列等。

这是有人说要做的,但我是不确定我是否在正确的位置添加了更新标签,因为它似乎不起作用。另外,如果您阅读他们说的评论,一旦您重新打开缓存,就会破坏它: http://www.lotusseedsdesign.com/blog/change-grid-view- column-4-product-listing

那么有谁知道如何使用 addColumnCountLayoutDepend 方法或任何其他方式来更改特定于页面布局的产品网格上的列数?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

岁月蹉跎了容颜 2024-10-26 15:46:52

对于子类别页面,在 app/design/frontend/Your Interface/layout/catalog.xml 中更改列值以下行:

<action method="setColumnCount"><columns>4</columns></action>

对于根类别页面,在 app/design/frontend/Your Interface/template/catalog/product/list 中。 phtml 在“网格模式”部分找到以下代码并更改为适当的值:

<?php $_columnCount = $this->getColumnCount(); ?>

例如

<?php $_columnCount = 4; ?>

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; ?>
梦里泪两行 2024-10-26 15:46:52

一个有点老的问题(几乎 3 年了:D),但我在 Kathir 'Sid' Vel 的网站

为此,您将编辑catalog/product/list.phtml 模板。

找到行:

<?php $_columnCount = $this->getColumnCount(); ?>

并替换为以下代码,或注释该行并在其后添加代码。

<?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;
}

?>

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;
}

?>
空名 2024-10-26 15:46:52

有几种方法可以更改列数。您可以尝试每种方法,看看哪种方法适合您。

1) 观看本教程:http://www.youtube.com/watch?v=wNbV34v72a0
这是使其工作所需的代码。

<reference name="product_list">
<action method="setColumnCount"><count>4</count></action>
</reference>

2) 如果上述方法失败,请在您想要更改列的任何 CMS 页面中使用此方法。例如:如果您有一个用于显示特定类别的 CMS 页面,请使用它。这对于显示特定类别产品并同时设置每行的项目数特别有用。在 CMS 页面中添加以下代码:

{{block type="catalog/product_list" category_id="42" template="catalog/product/showroom.phtml" columnCount="4"}} 

您可以将 columnCount 数字从 4 更改为您想要的任何值。您可以通过单击 magento admin/category/manage Category/ 下的类别来获取类别 id,

这非常重要!有时,当您在上述两个步骤中的任何一个中正确执行所有操作时,每行的项目仍然不会更改。原因很可能是 CSS 问题。这样就进入了步骤 3:

3) 打开模板的 CSS 并搜索 .products-grid
确保宽度设置为足够高的数字,以便能够显示所需的每行项目数,而不必向下推溢出的项目。就我而言,我尽了一切努力让每行有 4 个项目,但失败了,直到我在 CSS 中注意到我的 .col1-layout .products-grid 的宽度为 750px。我将宽度更改为 995px,瞧,第 2 步完美运行。

虽然已经晚了,但我希望它能对那里的人有所帮助。

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.

自控 2024-10-26 15:46:52

转到app\design\frontend\base\default\layout\catalog.xml
然后转到第 85 行并修改代码。找到“catalog/product_list_toolbar”,然后根据您的需要定制产品。

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.

仙女 2024-10-26 15:46:52

更改它的最简单方法是从配置选项卡

“系统”->“配置”->“配置”。目录选项卡-目录->前端,您可以从 magento 后端轻松更改它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文