Magento - 列出产品类别

发布于 2024-09-14 17:11:10 字数 61 浏览 4 评论 0原文

在 Magento 的每个产品详细信息页面上,我想列出属于哪些类别。

我将如何实现这一目标?

In Magento on each products detail page I would like to list which categories which belongs to.

How would I go about achieving this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

三生殊途 2024-09-21 17:11:10

尝试一下:

$currentCatIds = $_product->getCategoryIds();

还有

 $categoryCollection = Mage::getResourceModel('catalog/category_collection')
  ->addAttributeToSelect('name')
  ->addAttributeToSelect('url')
  ->addAttributeToFilter('entity_id', $currentCatIds)
  ->addIsActiveFilter();

干杯,
京东

Give this a try:

$currentCatIds = $_product->getCategoryIds();

and also

 $categoryCollection = Mage::getResourceModel('catalog/category_collection')
  ->addAttributeToSelect('name')
  ->addAttributeToSelect('url')
  ->addAttributeToFilter('entity_id', $currentCatIds)
  ->addIsActiveFilter();

Cheers,
JD

若相惜即相离 2024-09-21 17:11:10

您可以使用以下代码在商品详情页中显示与所选商品相关的所有类别。

<?php $categories = $_product->getCategoryIds(); ?>
           <?php foreach($categories as $k => $_category_id): ?>
           <?php $_category = Mage::getModel('catalog/category')->load($_category_id) ?> 
            <a href="<?php echo $_category->getUrl() ?>"><?php echo $_category->getName() ?></a>
           <?php endforeach; ?>

You can use the following code to display all categories related to the selected product in the product detail page.

<?php $categories = $_product->getCategoryIds(); ?>
           <?php foreach($categories as $k => $_category_id): ?>
           <?php $_category = Mage::getModel('catalog/category')->load($_category_id) ?> 
            <a href="<?php echo $_category->getUrl() ?>"><?php echo $_category->getName() ?></a>
           <?php endforeach; ?>
风柔一江水 2024-09-21 17:11:10

该代码将根据商店 ID 获取产品类别名称。这也将充分用于多商店和多网站概念

   $product = Mage::getModel('catalog/product')->load($product_id);
   $cats = $product->getCategoryIds(); 
   foreach ($cats as $category_id) {
   $_cat = Mage::getModel('catalog/category')->setStoreId(Mage::app()-  >getStore()->getId())->load($category_id);
    echo $_cat->getName();             
     }

The code will get product category name based on store id. This will also use full for multi store and multiwebsite concepts

   $product = Mage::getModel('catalog/product')->load($product_id);
   $cats = $product->getCategoryIds(); 
   foreach ($cats as $category_id) {
   $_cat = Mage::getModel('catalog/category')->setStoreId(Mage::app()-  >getStore()->getId())->load($category_id);
    echo $_cat->getName();             
     }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文