Magento Determine if Current Page is Category or Not

Sometimes you find your self in the need to determine if the current page a visitor is viewing is of a category or not. The reason for this could drastically very, but one good reason is the need for a global element not be shown on any category page.

It would be much faster to simply include this element or rather custom block globally to your Magento store via your layout XML files, and have a condition in this block’s .phtml file that excluded any output on category page.

This is a very simple method that simply looks to our Mage registry and asks the question “Is the current page indeed a current category page or not?”.

php if(!Mage::registry('current_category')):?>
php endif; ?>

Simple as that, of course the correct way would be to include this block globally via your XML layout files, and then remove it via XML (Custom Layout Update) in the backend->catalog->manage categories “Custom Design” tab for each category.

But this method might be faster.

Devin R. Olsen

Devin R. Olsen

Located in Portland Oregon. I like to teach, share and dabble deep into the digital dark arts of web and game development.

More Posts

Follow Me:
TwitterFacebookGoogle Plus