cancel
Showing results for 
Search instead for 
Did you mean: 

PHP: CategoryId not refreshing

SOLVED

PHP: CategoryId not refreshing

Hi All,

I need to hide a <div> with PHP on a specific page.

 

I'm using this script:

<?php
$category = Mage::registry('current_category');
if($category != null){
$categoryId = $category->getId();
}else $category ="null";

//print $categoryId;
?>

 

<?php if($categoryId != 176) : ?>

      <div>... html to be hide ...</div>

<?php endif; ?>

 

The code is working fine at first round, but if I navigate in the menù, switching from the page with Category 176 to the homepage, the GategoryId is fixed to 176 and viceversa (if I navigate first on HomePage the value of $category will be always Null).

 

Can anyone help?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: PHP: CategoryId not refreshing

Hi all,

thanks for your support, but the issue was linked to Magento cache, my script is correct.

 

I had to disable BLOCK_HTML cache type to have expected behavior.

View solution in original post

3 REPLIES 3

Re: PHP: CategoryId not refreshing

Hi @filippo_scifo1,

 

If you navigate first the Homepage the null result is right. Mage::registry('current_category') is filled when you enter into a category.

I guess you shouldn't apply that logic into the phtml. You should have a method into a block with a bool output and then, into the phtml you should ask for that value as true or false.

 

But also, I'm not sure if I have all the information about your issue. Maybe you can explain a little bit more?

Re: PHP: CategoryId not refreshing

Try it below approach

 

<?php 
if (!(Mage::registry('current_category') || Mage::registry('current_product))): $categoryId = $category->getId(); // Put your hide and show condition based on $categoryId. else: //Your Logic endif; ?>
-- Ravindra

Re: PHP: CategoryId not refreshing

Hi all,

thanks for your support, but the issue was linked to Magento cache, my script is correct.

 

I had to disable BLOCK_HTML cache type to have expected behavior.