I have this code snippet which works for displaying content depending on which top category the product belongs to:
<?php $categoryIds = $_product->getCategoryIds(); if($categoryIds[0]!= '42'):?>
CONTENT HERE...
<?php endif; ?>
This is put in the list.phtml and view.phtml under catalog/product in Magento 1.6.1 Community Edition. This code works for one ID but when I try adding:
<?php $categoryIds = $_product->getCategoryIds(); if($categoryIds[0]!= '42' || $categoryIds[1]!= '43'):?>
CONTENT HERE...
<?php endif; ?>
it doesn’t work anymore. Can some of you Magento Wizards help a poor soul out?!
Thanks in advance.
Previous post from Guerra is almost correct. He only messed up a little with logic – you need logical AND instead of OR there:
otherwise the case will return true both for 42 and 43 categories (because of OR).