基于产品页面的类别ID magento的条件加载内容
问题描述:
我想有条件地根据产品页面中的类别ID加载内容,但是无法正常工作.我知道我可以通过调用自定义属性来做到这一点,但这并不是我要记住的,因为内容专门针对特定类别,因此我不想在给定类别的每种产品中重复输入.
I want to conditionally load content based on category id in product page but can't get it to work. I know I can do this by calling a custom attribute but this is not what I have in mind because the content is specifically for a particular category so I don't want to enter it repeatedly in each product for the given category.
基本上我正在寻找这样的东西:
Basically I was looking for something like this:
<?php if ($_catid = $this->getCategoryid('3')):?>
display content for category id 3 (content is entered directly in the view.phtml file)
<?php else: ?>
content for other cateogegory
<?php endif; ?>
非常感谢您的指导!
更新正确的代码(感谢ahadley):
Update for the correct code (thanks ahadley):
<?php $category = Mage::getModel('catalog/layer')->getCurrentCategory();?>
<?php if($category->getId()==3): ?>
<h3>Show content for Category ID3</h3>
<?php else: ?>
<h3>Show content for other categories</h3>
<p>consectetuer adipiscing elit. </p>
<?php endif; ?>
答
您可以使用类似以下的内容来加载类别:
You could use something like the following to load the category:
<?php $category = Mage::getModel('catalog/layer')->getCurrentCategory();?>
然后您可以获得以下信息:
Then you could get information such as:
<?php echo $category->getName();?>