【问题标题】:Magento: how do you change the number of product columns based upon page layout?Magento:您如何根据页面布局更改产品列的数量?
【发布时间】:2014-09-23 20:27:42
【问题描述】:

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

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

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

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

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

【问题讨论】:

  • 请更新您的问题以包含您修改的 XML 部分。另外,您的意思是即使缓存关闭,它也会损坏?
  • 我从来没有让链接中的方法起作用。其他人则表示该方法在启用布局缓存后中断。我没有发布我修改的 XML,因为它会使问题变得很大。我只是想找到任何合理的方法来允许不同的布局显示不同的产品行大小。

标签: magento


【解决方案1】:

对于子类别页面,在 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; ?>

【讨论】:

    【解决方案2】:

    一个有点老的问题(差不多 3 年了:D),但我在 Kathir 'Sid' Vel's site 上找到了一个有趣的解决方案

    为此,您将编辑目录/产品/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;
    }
    
    ?>
    

    【讨论】:

      【解决方案3】:

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

      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。我将宽度更改为 995 像素,瞧,第 2 步完美运行。

      这已经晚了,但我希望它可以帮助那里的人。

      【讨论】:

      • 为了避免在小部件中回复相同的内容,只需使用:{{widget type="catalog/product_widget_new" display_type="all_products" show_pager="1" products_per_page="6" products_count=" 12" column_count="3" template="catalog/product/widget/new/content/new_grid.phtml"}}。注意 column_count 而不是 block 调用中的 columnCount。
      【解决方案4】:

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

      【讨论】:

      • 在 1.9.2.4 的第 105 行和第 152 行: 3
      【解决方案5】:

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

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

      【讨论】:

      • Magento CE 1.9.1.0 中没有该选项
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多