代码之家  ›  专栏  ›  技术社区  ›  a1anm

Magento-列出产品类别

  •  3
  • a1anm  · 技术社区  · 16 年前

    我该如何实现这一目标?

    3 回复  |  直到 16 年前
        1
  •  5
  •   Jonathan Day    16 年前

    试一试:

    $currentCatIds = $_product->getCategoryIds();
    

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

    干杯,

        2
  •  1
  •   Sarath Tomy    14 年前

    您可以使用以下代码在产品详细信息页面中显示与所选产品相关的所有类别。

    <?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; ?>
    
        3
  •  0
  •   Sathish Kumar VG    9 年前

       $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();             
         }
    
    推荐文章