0

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. :D

Thanks in advance.

| improve this question | | | | |
0

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; ?>
| improve this answer | | | | |
0

you can use in_array function for that.

$os = array(3,4,5,6);
if (in_array($_category->getId(), $os)) {
    echo "Got id";
}else {
echo "not";
}
| improve this answer | | | | |
0
if(in_array($_category->getId(),array(3,4,5,6))){

}else{

}
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.