1

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 2

1
  1. Login to admin panel
  2. Goto catalog-->manage categories
  3. Select category which you want to change the title
  4. Goto display options and enter there your desire page title
  5. Save category
  6. clear cache and refresh website frontend.
3
  • thank you for your answer.but it is a difficult solution and need to add title for every category.but i need it programmatically
    – Asha
    Oct 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
  • if you are aware of this answer please post ..
    – Asha
    Oct 20, 2016 at 6:45
0

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));

                }
            }
        }

}
3
  • hi,this is not working
    – Asha
    Oct 20, 2016 at 8:52
  • Have u create full module?
    – Amit Bera
    Oct 20, 2016 at 8:56
  • no.please describe detaily
    – Asha
    Oct 20, 2016 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.