Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

If category id = x show static block
 
garryj87@hotmail.com
Jr. Member
 
Total Posts:  3
Joined:  2010-09-07
 

Hello,

I have been trying to figure this out for hours now and nothing really helps. Could you please help me out.

What i am trying to do is display a static block in my footer. But only show up if I\\\’m on a particular category or page.

This is basically what I am after to display before my footer.

if (current page category id 4
{
display 
static block "footer_4"
}
elseif (current page category id 5)
{
display 
static block "footer_5"
}
else
{
display 
static block "default_block"
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
VnEcoms
Sr. Member
 
Avatar
Total Posts:  121
Joined:  2012-09-13
Vietnam
 

you can use Mage::registry(...) to get current category:

$categoryId Mage::registry('current_category')?Mage::registry('current_category')->getId():'';
switch(
$categoryId ){
    
case 4:
    
//Display Static block [b]footer_4[/b] here
    
break;
    
//....
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
garryj87@hotmail.com
Jr. Member
 
Total Posts:  3
Joined:  2010-09-07
 

Thank you so much for the reply. But unfortunately that didn’t work :(

This is the code I’m using

<?php
$categoryId 
Mage::registry('current_category')?Mage::registry('current_category')->getId():'';
switch(
$categoryId ){
case 13:
echo 
"Display Static block footer_13 here";
break;
echo 
"....";
}
?>

It\’s a little strange though.. because it doesn’t echo “Display static block footer 13” or “....”

Any suggestions?

 
Magento Community Magento Community
Magento Community
Magento Community
 
VnEcoms
Sr. Member
 
Avatar
Total Posts:  121
Joined:  2012-09-13
Vietnam
 

did you check the value of $categoryId? try to echo $categoryId;
i did give you a right code.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

I think the problem is that the footer is cached.
And the cache key does not depend on the current category.
Disable the block cache and see if it works.
And even if it works without the block cache this still doesn’t solve your problem but at least you know you are on the right track.
If you make it work without the cache then you need to override this method Mage_Page_Block_Html_Footer::getCacheKeyInfo() to look something like this:

public function getCacheKeyInfo()
    
{
        $cacheKey 
=  array(
            
'PAGE_FOOTER',
            
Mage::app()->getStore()->getId(),
            (int)
Mage::app()->getStore()->isCurrentlySecure(),
            
Mage::getDesign()->getPackageName(),
            
Mage::getDesign()->getTheme('template'),
            
Mage::getSingleton('customer/session')->isLoggedIn()
        );
if (
Mage::registry('current_category')){
$cacheKey[] 
Mage::registry('current_category')->getId();
}
return $cacheKey;
    
}

Marius.

 
Magento Community Magento Community
Magento Community
Magento Community
 
garryj87@hotmail.com
Jr. Member
 
Total Posts:  3
Joined:  2010-09-07
 

Thanks guys, it seems like it was the cache problem.

Could you please explain this more:

If you make it work without the cache then you need to override this method Mage_Page_Block_Html_Footer::getCacheKeyInfo() to look something like this:

I don\’t know what you mean.

 
Magento Community Magento Community
Magento Community
Magento Community
 
cse8668
Jr. Member
 
Total Posts:  15
Joined:  2012-01-12
 

My way is to get categories ids ,than equal to categories ID numbers.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

Basically you need to modify the way that method works, and in order not to alter the core code Magento allows you to use your own class instead of the one in the core.
Here is a good tutorial on how to override a block model or helper.
http://magedev.com/2009/06/03/magento-overriding-model-block-or-helper/

It works even if you change the code in the core file but that will make your website ‘un-upgradable’.

Marius.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top