简体   繁体   English

在magento中,如何为不同的类别显示不同的list.phtml和view.phtml?

[英]In magento how can I show different-different list.phtml and view.phtml for different -different categories?

I want to show different -different list.phtml and view.phtml for different-different categories . 我想为不同的类别显示不同的-different list.phtmlview.phtml

My code is: 我的代码是:

<CATEGORY_4>
    <reference name="product_list">
    <action method="setTemplate"><name>catalog/product/list_new.phtml</name></action>
</reference>
</CATEGORY_4>

Your code will help you use different list.phtml for different categories. 您的代码将帮助您将不同的list.phtml用于不同的类别。 To use different view.phtml for different category products, you will have to set different attribute attribute sets and assign different templates for different attributes set. 要将不同的view.phtml用于不同的类别产品,您将必须设置不同的属性属性集,并为不同的属性集分配不同的模板。 Check this link to how to do it Magento: template based on attribute set 检查此链接以了解如何操作Magento:基于属性集的模板

OR 要么

If both the category page and product view page use the same page layout,for eg: category page and product view page uses 1column.phtml page layout, you can use different list.phtml and view.phtml for different categories by following these steps. 如果类别页面和产品视图页面使用相同的页面布局,例如:类别页面和产品视图页面使用1column.phtml页面布局,则可以按照以下步骤为不同的类别使用不同的list.phtmlview.phtml

  1. In the admin panel goto Catalog > Manage categories 在管理面板中,转到目录>管理类别
  2. Select the category for which you want to change the list.phtml 选择您要更改列表的类别。phtml
  3. Select " Custom Design " tab. 选择“ 自定义设计 ”标签。
  4. Set " Use parent category settings " to No and " Apply to products " to Yes. 将“ 使用父类别设置设置为 “否”,并将“ 应用于产品设置 “是”。
  5. Add this in the " Custom Layout Update " section 将其添加到“ 自定义布局更新 ”部分
  <reference name="product_list"> <action method="setTemplate"><name>catalog/product/your-list-filename.phtml</name></action> </reference> <reference name="product.info"> <action method="setTemplate"><template>catalog/product/your-view-filename.phtml</template></action> </reference> 

Repeat this for all the categories that you want to change. 对要更改的所有类别重复此操作。

Thanks for the post. 感谢您的帖子。 i just used this one 我只是用这个

<reference name="product.info">
    <action method="setTemplate"><template>catalog/product/your-view-filename.phtml</template> </action>
</reference>

and it's working fine. 而且工作正常。 but if i set one product in multiple categories so it's not handle the layout. 但是如果我将一种产品设置为多个类别,则无法处理布局。 it's call same file "your-view-filename.phtml". 它称为同一文件“ your-view-filename.phtml”。 even i go through from both categories. 甚至我都经历过这两个类别。

With method: 使用方法:

<reference name="product.info">
    <action method="setTemplate"><template>catalog/product/your-view-filename.phtml</template> </action>
</reference>

product layout is only applied when you visit product from the category page where you have defined it. 仅当您从定义产品的类别页面访问产品时,才应用产品布局。 If you visit product from homepage, for example, it's not applied. 例如,如果您从主页访问产品,则该产品不适用。 What I have done to apply layout to all products that belong to a defined category is to rewrite function getDesignSettings() from Mage_Catalog_Model_Design: 我将布局应用于属于已定义类别的所有产品所做的工作是从Mage_Catalog_Model_Design重写函数getDesignSettings():

public function getDesignSettings($object)
{
    if ($object instanceof Mage_Catalog_Model_Product) {
        $customCat = 'XX';
        $productCats = $object->getAvailableInCategories();

        if (in_array($customCat, $productCats))
            $currentCategory = Mage::getModel('catalog/category')->load($customCat);
        else
            $currentCategory = $object->getCategory();
    } else {
        $currentCategory = $object;
    }

    $category = null;
    if ($currentCategory) {
        $category = $currentCategory->getParentDesignCategory($currentCategory);
    }

    if ($object instanceof Mage_Catalog_Model_Product) {
        if ($category && $category->getCustomApplyToProducts()) {
            return $this->_mergeSettings($this->_extractSettings($category), $this->_extractSettings($object));
        } else {
            return $this->_extractSettings($object);
        }
    } else {
         return $this->_extractSettings($category);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM