Magento – issue in Mage::registry(‘current_category’), return only the same value for whole category pages

catalogcategorymagento-1.7

When its come to Mage::registry('current_category'); is a common question.

After searching several pages,stack exchange and stack overflow i feel to post this question as i am unable to find a solution for this.and willing to get some advice to get from the helping mind in the community.

I want to update different content for different category pages in my website.

I use this code to get the current category and define the footer contents.

I added this code in to my footer.phtml and echo the $footer_content

$current_category = Mage::registry('current_category')->getName();
if($current_category=='All Deals'){
    $footer_content ="Content #1";
}
if($current_category=='Food & Dining'){
    $footer_content ="Content #2";
}

this code segment always return the one value for different category pages.
What is the issue i am facing,it will be great pleasure if some one can explain any possible suggestion to fix this issue.

Best Answer

It totally cache issue.In your system, their have strong caching. of footer section.You need to disable this case by using layout code or rewrite your block class.

In layout you need to set footer block cache life time null that case will disable for this section.

<reference name="footer">
    <action method="setCacheLifetime"><s>null</s></action>
</reference>

Also for your coding there issue.

You need to fix this.

if(Mage::registry('current_category')): // to prevent the error rest of pages except category &product page
  $current_category = Mage::registry('current_category')->getName();
  if($current_category=='All Deals'){
      $footer_content ="Content #1";
  }
  if($current_category=='Food & Dining'){
      $footer_content ="Content #2";
  }
endif;