基于产品页面的类别ID magento的条件加载内容 [英] Conditional loading content based on category id magento for product page

查看:65
本文介绍了基于产品页面的类别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();?>

这篇关于基于产品页面的类别ID magento的条件加载内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆