【问题标题】:Magento: Titles for some categories but not for allMagento:某些类别的标题,但不是所有类别的标题
【发布时间】:2011-12-02 16:03:53
【问题描述】:

我需要在某些类别上使用标题标签,但不是全部。它们是默认显示的,所以到目前为止我所做的是在 app/design/frontend/default/my_theme/template/catalog/category 中创建一个新的 view.phtml 文件并注释掉创建标题的部分,这工作正常. 下一阶段将启用某些类别的标题。我通过手动将其添加到类别描述中来做到这一点,这很好,但后来我想到了可能创建一个 cms 块并使用它来完成它。为此,需要一个标记标签或其他东西来显示我可以放在静态块中的当前类别。有吗?..还是有其他方法可以做到这一点?

(我已经包含了背景故事,因为这可能是在类别页面上完全关闭标题的错误方法。)

【问题讨论】:

    标签: magento


    【解决方案1】:

    你可以这样做

    <layout>
         <your_target_handler>
               <reference name="head">
                    <action method="setTitle"><title>Your title</title></action>
               </reference>
         </your_target_handler>
    </layout>
    

    或者通过php实现

    $this->getLayout()->getBlock('head')->setTitle('my title');
    

    Mage::app()->getLayout()->getBlock('head')->setTitle('my title');
    

    【讨论】:

    • 对不起,也许我不明白,或者我没有在问题中说清楚,但重点是让标题动态
    • 非常感谢 - 看起来它会起作用 - 我已经离开这个项目几天但会稍后尝试
    【解决方案2】:

    您还可以为类别添加一个额外的属性,用作显示或不显示标题的开关(无论哪种方式最简单)。 然后调整模板代码,使其检查是否必须显示标题。

    我使用以下代码在 Mage 1.5.0 中为类别添加额外的 (textarea) 属性:

    /* ADD ATTRIBUTES TO MAGENTO BACKEND FOR CATEGORIES 
     * Adding the type
     */
    INSERT INTO eav_attribute (entity_type_id, attribute_code, backend_type, frontend_input, frontend_label, default_value, source_model) 
    VALUES (9, 'category_from_data', 'text', 'textarea', 'From pricing text', '', '');
    
    /*
     * Source Q:
     * INSERT INTO eav_entity_attribute ( entity_type_id, attribute_set_id, attribute_group_id, attribute_id, sort_order ) VALUES ( 3, 3, 3, <new attribute ID>, <next sort order> );
     * Works but entity_type_id should be 9 for category
     */
    INSERT INTO eav_entity_attribute ( entity_type_id, attribute_set_id, attribute_group_id, attribute_id, sort_order ) VALUES ( 9, 12, 7, 9, 25 );
    
    /* 
     * Adding the attribute itself
     */
    INSERT INTO `catalog_eav_attribute` (`attribute_id`, `frontend_input_renderer`, `is_global`, `is_visible`, `is_searchable`, `is_filterable`, `is_comparable`, `is_visible_on_front`, `is_html_allowed_on_front`, `is_used_for_price_rules`, `is_filterable_in_search`, `used_in_product_listing`, `used_for_sort_by`, `is_configurable`, `apply_to`, `is_visible_in_advanced_search`, `position`, `is_wysiwyg_enabled`) VALUES
    (977, NULL, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, '', 0, 0, 1);
    

    您可能想检查数据库本身并找出 eav_entity_attribute 中包含的 entity_type_id 9 以及第一次查询后 eav_attribute 中的插入 id 是什么。

    对于添加复选框属性,我建议您检查表并查找现有属性并相应地调整查询中的参数。

    希望这会有所帮助;)

    【讨论】:

    • 听起来可以,谢谢-我是magento的新手-我知道在哪里设置产品属性,但是我在哪里设置类别属性?
    • @buronyasgur 我添加了为我完成这项工作的 SQL。看看它是否对您有帮助,或者至少可以为您指明正确的方向......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多