Magento: Titles for some categories but not for all
I need to have title tags on certain categories but not on all. They are displayed by default so what I've done so far is to create a new view.phtml file in app/design/frontend/default/my_theme/template/catalog/category and comment out the section creating the title, which works fine. The next stage would be to enable the title on some of the categories. I did this by adding it manually to the category description which is ok but then i got the idea of maybe creating a cms block and using that to do it. To do this th开发者_运维知识库ere would need to be a markup tag or something to display the current category which I could put in the static block. Is there?.. or is there any other way of doing this?
( I have included the backstory because maybe this is the wrong way to go about turning the title off on category pages altogether.)
you can do that with
<layout>
<your_target_handler>
<reference name="head">
<action method="setTitle"><title>Your title</title></action>
</reference>
</your_target_handler>
</layout>
or do it via php
$this->getLayout()->getBlock('head')->setTitle('my title');
or
Mage::app()->getLayout()->getBlock('head')->setTitle('my title');
You could also add an extra attribute to a category which works as a switch for showing or not showing the title (whichever way is the easiest). Than adjust the template code so it will check if the title must be displayed or not.
I used the following code to add extra (textarea) attributes to categories in Mage 1.5.0:
/* 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);
You might want to check the db itself and find out what entity_type_id 9 holds in eav_entity_attribute and what the insert id in eav_attribute is after 1st query.
For adding a checkbox attribute I suggest you check the tables and fish for an existing attribute and adjust the parameters in the query accordingly.
Hope this helps ;)
精彩评论