以下是代码片段:

   $_categoryIds = $_product->getCategoryIds();

   foreach ($_categoryIds as $_categoryId) {
      $_category = Mage::getModel('catalog/category')->load($_categoryId);

      $_category_name = $_category->getName();
      $_category_url  = $_category->getUrlPath();

      break;
   }


由于在Magento中,一个产品可以加入到多个分类中,可以通过foreach循环来获取多个categoryId,这里只取了第一个分类的Id。 据我所知,这些分类没有主次之分,不像Zen Cart中有master category这样的概念。