I show dynamic content depending on category. The code works perfectly fine, except I would like to combine multiple getId in 1 if statement. Currently every category Id is called per if or elsif statement. Wich gives me a lot of extra code. Is it possible to combine mulitple category id's in 1 if statement???
The current code:
<?php $category = Mage::getModel('catalog/layer')->getCurrentCategory();?>
<?php if($category->getId()==1): ?> text 1
<?php elseif($category->getId()==2): ?> text 1
<?php elseif($category->getId()==3): ?> text 1
<?php else: ?> text 2
<?php endif; ?>
I usually do this by using the in_array() function. So:
<?php
$myValidIds = array(1,2,3);
if(in_array($category->getId(), $myValidIds)){
// Do something....
}
?>
A simple in_array would suffice.
$allowed = array('1', '2', '3');
if (inarray($category->getId(), $allowed)){
//it exists, show text 1
}else{
//it doesnt exist, show text 2
}
Why not
$cat = $category->getId();
if($cat==1) ...
?
If "text 1" is provided whenever id equals 1, 2, or 3 why can't you just type
<?php if($category->getId()==1 || $category->getId()==2 || $category->getId()==3): ?> text 1
?