【问题标题】:Displaying Current Sub-Category name on Magento Product page在 Magento 产品页面上显示当前子类别名称
【发布时间】:2014-07-22 11:23:34
【问题描述】:

我目前在一家 magento 商店工作,我需要在产品页面中显示产品当前子类别的名称和 url。到目前为止,我已经想出了以下代码。

<?php $categories = $_product->getCategoryIds(); ?>

                <?php 


                foreach($categories as $k => $_category_id):

                $_category = Mage::getModel('catalog/category')->load($_category_id) 



                ?>


                <a href="<?php echo $_category->getUrl() ?>"><?php echo $_category->getName() ?></a>


                <?php endforeach; ?>

但问题是这会显示产品分配到的所有类别。我所需要的只是产品被分配到的唯一子类别的名称。谢谢。

【问题讨论】:

  • 您的产品是只分配到一个类别还是多个类别?
  • 产品被分配到多个类别..

标签: php magento magento-1.8


【解决方案1】:

有很多方法。最快和最容易使用 thr Magentk Registry。所以试试下面的代码:

$category = Mage::registry('current_category')

或者

$categoryIds = Mage::registry('current_product')->getCategoryIds();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-15
    • 1970-01-01
    • 2019-08-09
    • 1970-01-01
    • 1970-01-01
    • 2021-09-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多