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?
Solved! Go to Solution.
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.
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?
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; ?>