【问题标题】:magento product grid with 4 columns only on 1 column template仅在 1 列模板上具有 4 列的 magento 产品网格
【发布时间】:2013-10-24 17:50:12
【问题描述】:

我想让产品列表页面使用 4 列而不是 3 列(默认) 我发现如果我使用

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

在类别布局更新(从后端)上它工作正常。我还发现了许多帖子,这些帖子描述了如何为所有页面布局制作 4 列网格。

我只需要在一栏页面上使用 4 栏网格。我把它放在我的 local.xml 上,但它不起作用..

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

我做错了什么?谢谢

【问题讨论】:

    标签: magento layout


    【解决方案1】:

    进入管理员

    2) 目录->管理类别

    3) 在我的示例手机

    中选择您想成为一个列布局的类别

    4) 点击自定义设计

    5)

    Use Parent Category Settings = no
    
    Page Layout = 1 column
    Custom Layout Update 
    
    <reference name="product_list">
            <action method="setColumnCount"><columns>4</columns></action>
        </reference>
    

    希望对您有所帮助 1)

    或替代解决方案

    app/design/frontend/default/[yourtheme]/template/catalog/product/list.phtml

    第 89 行

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

    将上面的代码替换为

     <?php $_collectionSize = $_productCollection->count() ?>
        <?php $pageLayout=$this->getLayout()->getBlock('root')->getTemplate(); ?>
        <?php if ($pageLayout="page/1column.phtml"):?>
            <?php $_columnCount = 4 ?>
        <?php else: ?>  
            <?php $_columnCount = $this->getColumnCount(); ?>
        <?php endif; ?>
    

    【讨论】:

    • 编辑:堆栈不允许我编辑我以前的评论。正如我所说的“定制设计”方法对我没有用,因为我需要这个用于所有 1 列布局。替代解决方案代码编辑可以工作,但我想用布局 xml 来做。这也是我的问题的目的。如果仅使用 xml 更新无法完成我需要的操作,我将使用您提供的 php 方法。谢谢
    【解决方案2】:

    打开app/design/frontend/default/default/layout/catalog.xml

    根据您的要求定义列数

    <catalog_category_default>,<catalog_category_layered> 
    

    如果你想在&lt;catalogsearch_result_index&gt;中设置列数

    在中打开和编辑

    打开app/design/frontend/default/default/layout/catalogsearch.xml

    <action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
    <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>4</count></action>
    <action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>
    <action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
    <action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>
    

    现在在

    中定义观察者
    app/code/core/Mage/Catalog/etc/config.xml
    

    &lt;events&gt;中添加以下代码

        <catalog_controller_category_init_after>
              <observers>
                    <custom_page_layout>
                        <class>catalog/observer</class>
                             <method>addHandle</method>
                    </custom_page_layout>
               </observers>
      </catalog_controller_category_init_after>
    

    现在打开

     app/code/core/Mage/Catalog/Model/Observer.php
    

    添加如下函数

    public function addHandle($observer)
        {
            $controllerAction = $observer->getEvent()->getControllerAction();
            $category = $observer->getEvent()->getCategory();
            if ($category->getPageLayout()) {
                    $controllerAction->getLayout()->helper('page/layout')
                        ->applyHandle($category->getPageLayout());
                }
        }
    

    进入管理员

    2) 目录->管理类别

    3) 选择你想成为一栏布局的类别

    4) 点击自定义设计

    5) 使用父类别设置 = 否 页面布局 = 1 列

    注意:不要在核心中编辑,而是创建新模块并定义上面的观察者

    希望对你有帮助

    【讨论】:

    • 是否可以只更新布局而不编辑(覆盖)任何核心代码?只需使用 local.xml 或其他东西..
    • 如果不更改或覆盖核心文件是不可能的
    • local.xml 用于布局目的,而不是用于配置或设置。或者您可以在其中创建模块并定义上述代码
    猜你喜欢
    • 1970-01-01
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多