Magento – If the current category ID exists in this array of IDs, then show something

category

I'm new to Magento, and I would like to know how to add a condition like my title above.

If the current category page is 3, or 4, or 5, or 6, then I need to show something.

Provided that _category is equal to $this->getCurrentCategory, all I can think of is this:

<?php if($_category->getId()==array(3,4,5,6): ?>
// Stuff to show if the current cat is 3 or 4 or 5 or 6
<?php else: ?>
//Stuff to show for other categories
<?php endif; ?>

But it doesn't work. I assume that my usage of array is wrong or I missed something. I hope I Magento/PHP expert can enlighten me. 😀

Thanks in advance.

Best Answer

Use in_array()

Below condition shall work for you

<?php if(in_array($_category->getId(), array(3,4,5,6))): ?>
// Stuff to show if the current cat is 3 or 4 or 5 or 6
<?php else: ?>
//Stuff to show for other categories
<?php endif; ?>
Related Topic