基于产品页面的类别id magento有条件加载内容

基于产品页面的类别id magento有条件加载内容,magento,Magento,我想根据产品页面中的类别id有条件地加载内容,但无法使其正常工作。我知道我可以通过调用自定义属性来实现这一点,但这不是我想要的,因为内容是专门针对特定类别的,所以我不想在给定类别的每个产品中重复输入它 基本上我是在找这样的东西: <?php if ($_catid = $this->getCategoryid('3')):?> display content for category id 3 (content is entered directly in the view.p

我想根据产品页面中的类别id有条件地加载内容,但无法使其正常工作。我知道我可以通过调用自定义属性来实现这一点,但这不是我想要的,因为内容是专门针对特定类别的,所以我不想在给定类别的每个产品中重复输入它

基本上我是在找这样的东西:

<?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; ?>

显示类别id 3的内容(直接在view.phtml文件中输入内容)
其他类别的内容
非常感谢您的指导

更新正确的代码(感谢ahadley):


显示类别ID3的内容
显示其他类别的内容
献祭者,献祭精英


您可以在
产品/视图中执行类似操作。phtml
模板:

<?php if (Mage::registry('current_category') == 3): ?>
// display content for category with the ID 3
<?php else: ?>
// content for other categories
<?php endif; ?>

//显示ID为3的类别的内容
//其他类别的内容

您可以在
产品/视图中执行类似操作。phtml
模板:

<?php if (Mage::registry('current_category') == 3): ?>
// display content for category with the ID 3
<?php else: ?>
// content for other categories
<?php endif; ?>

//显示ID为3的类别的内容
//其他类别的内容

您可以使用类似以下的方法加载类别:

<?php $category = Mage::getModel('catalog/layer')->getCurrentCategory();?>

然后您可以获得以下信息:

 <?php echo $category->getName();?>

您可以使用类似以下的方法加载类别:

<?php $category = Mage::getModel('catalog/layer')->getCurrentCategory();?>

然后您可以获得以下信息:

 <?php echo $category->getName();?>

这是最终代码,工作正常

 <?php if (Mage::registry('current_category') && Mage::registry('current_category')->getId() == 290) { ?>
    <?php 
        $categoryIds = $_product->getCategoryIds();                         
         $m = Mage::getModel('catalog/category')
                ->load($categoryIds[0])
                ->getParentCategory();
            echo $m->getName();
    ?>
    <?php } else ?>
    <?php if (Mage::registry('current_category') && Mage::registry('current_category')->getId() == 202) { ?>
    <?php 
        $categoryIds = $_product->getCategoryIds();                         
         $m = Mage::getModel('catalog/category')
                ->load($categoryIds[2])
                ->getParentCategory();
            echo $m->getName();
    ?>
    <?php } else { ?>
    <?php 
        $categoryIds = $_product->getCategoryIds();                         
         $m = Mage::getModel('catalog/category')
                ->load($categoryIds[1])
                ->getParentCategory();
            echo $m->getName();
    ?>
    <?php } ?>

这是最终代码,工作正常

 <?php if (Mage::registry('current_category') && Mage::registry('current_category')->getId() == 290) { ?>
    <?php 
        $categoryIds = $_product->getCategoryIds();                         
         $m = Mage::getModel('catalog/category')
                ->load($categoryIds[0])
                ->getParentCategory();
            echo $m->getName();
    ?>
    <?php } else ?>
    <?php if (Mage::registry('current_category') && Mage::registry('current_category')->getId() == 202) { ?>
    <?php 
        $categoryIds = $_product->getCategoryIds();                         
         $m = Mage::getModel('catalog/category')
                ->load($categoryIds[2])
                ->getParentCategory();
            echo $m->getName();
    ?>
    <?php } else { ?>
    <?php 
        $categoryIds = $_product->getCategoryIds();                         
         $m = Mage::getModel('catalog/category')
                ->load($categoryIds[1])
                ->getParentCategory();
            echo $m->getName();
    ?>
    <?php } ?>


谢谢,但它只排除ID 3中的内容。您到底想做什么?我的答案怎么了?我不明白你的意思…对不起,我不清楚。我通过针对不同的cat id再次测试了您的代码&现在我相信代码不起作用。特定ID(如3)中的目标内容未显示。仅显示后的内容,而不考虑任何类别中的产品(包括目标类别和第一次显示时给我的错误印象是代码有效,并排除了目标类别中的内容)。我正在使用v1.6,不确定这是否是原因!?谢谢,但它只排除ID 3中的内容。您到底想做什么?我的答案怎么了?我不明白你的意思…对不起,我不清楚。我通过针对不同的cat id再次测试了您的代码&现在我相信代码不起作用。特定ID(如3)中的目标内容未显示。仅显示后的内容,而不考虑任何类别中的产品(包括目标类别和第一次显示时给我的错误印象是代码有效,并排除了目标类别中的内容)。我正在使用v1.6,不确定这是否是原因!?也谢谢你,但我不知道如何才能针对我想要为Cat ID显示的内容(只是普通html内容)。此方法似乎只允许我加载当前类别的现有属性/元素。它可能有点夸张。它将允许您获取类别的属性。因此可以在条件语句中使用
->getId()
或类似的语句<代码>如果($category->getName()=“test”)执行此操作或
如果($category->getId()==5)这样做;
那样做。再次感谢您提供更多信息。我现在就知道了。希望这也能帮助其他人,我在我的问题中发布了完整的代码。由于设计问题,我意识到上面的方法不是最好的方法,因为它只限于给定的块(虽然这是可以修复的,但并不漂亮)所以我有另一个问题,希望我可以在不接触太多CSS代码的情况下快速完成:我想将cat ID 3作为块的目标,而不是另一个cat ID(例如,4)对于另一个块,我使用
显示类别ID3的内容
=类别ID4的内容
删除了
。但这会删除给定类别中的所有内容。我通过保持
并清空其后面的内容使其工作。为了显示另一个目标cat ID的内容,我需要重新设置转换另一个id的内容顺序,并且只能针对一个id,例如:
id 4的内容//将其保留为空,以便在id 3中不显示任何内容
//将其保留为空,以便id 3的id 4内容中不显示任何内容
不漂亮!也谢谢您,但我不知道如何针对内容我想为Cat ID显示的nt(只是普通html内容)。此方法似乎只允许我加载当前类别的现有属性/元素。它可能有点夸张。它允许您获取类别的属性。因此可以在条件中使用
->getId()
或类似方法。
if($category->getName()=“test”)做这件事;
如果($category->getId()==5)做这件事;
诸如此类的事。再次感谢您提供更多信息。我现在就知道了。希望这对其他人也有帮助。我在我的问题中发布了完整的代码。由于设计问题,我意识到上面的方法不是最好的方法,因为它只限于给定的块(虽然这是可以修复的,但并不漂亮)所以我有另一个问题,希望我可以在不接触太多CSS代码的情况下快速完成:我想将cat ID 3作为块的目标,而不是另一个cat ID(例如,4)对于另一个块,我使用
显示类别ID3的内容
=类别ID4的内容
删除了
。但这会删除给定类别中的所有内容。我通过保持
并清空其后面的内容使其工作。为了显示另一个目标cat ID的内容,我需要重新设置转换另一个id的内容顺序,并且只能针对一个id,例如:
id 4的内容//保持为空,以便在id 3中不显示任何内容
//保持为空,以便在id 3的id 4内容中不显示任何内容
不漂亮!