I am using magento 1.7 and i want to display the category title(meta title) as in the format of [Sub-Sub-Category] - [Sub-Categories] | main category
for all sub-sub-categories.
2 Answers
- Login to admin panel
- Goto catalog-->manage categories
- Select category which you want to change the title
- Goto display options and enter there your desire page title
- Save category
- clear cache and refresh website frontend.
-
thank you for your answer.but it is a difficult solution and need to add title for every category.but i need it programmatically– AshaOct 20, 2016 at 6:40
-
If you think this is also useful through admin panel, please upvote bro. if i get the solution , sure i will post programmatically Oct 20, 2016 at 6:44
-
In this case,you need to change do some code.
First,you need call an observer on event core_block_abstract_to_html_before
And on Mage_Page_Block_Html_Head
class update your page title
config.xml code:
<?xml version="1.0"?>
<config>
......
<models>
<changecategorytitle>
<class>Devamitbera_Changecategorytitle_Model</class>
</changecategorytitle>
</models>
......
</global>
<frontend>
<events>
<core_block_abstract_to_html_before> <!-- identifier of the event we want to catch -->
<observers>
<core_block_abstract_to_html_before_handler> <!-- identifier of the event handler -->
<type>model</type> <!-- class method call type; valid are model, object and singleton -->
<class>changecategorytitle/observer</class> <!-- observers class alias -->
<method>updatePageTitle</method> <!-- observer's method to be called -->
<args></args> <!-- additional arguments passed to observer -->
</core_block_abstract_to_html_before_handler>
</observers>
</core_block_abstract_to_html_before>
</events>
</frontend>
......
</config>
Observer
<?php
class Devamitbera_Changecategorytitle_Model_Observer
{
public function updatePageTitle(Varien_Event_Observer $observer){
$block = $observer->getBlock();
if($block instanceof Mage_Page_Block_Html_Head) {
/* sub -sub category level always be 4 */
if(Mage::registry('current_category') && Mage::registry('current_category')->getLevel() > = 4){
$_category = Mage::registry('current_category');
$pathInStore = $_category->getPathInStore();
$categories = $_category->getParentCategories();
$pathIds = explode(',', $pathInStore);
$title =array();
foreach ($pathIds as $categoryId) {
if (isset($categories[$categoryId]) && $categories[$categoryId]->getName()) {
$title[$categoryId] = $categories[$categoryId]->getName();
}
}
$block->setTitle(implode('-', $title));
}
}
}
}