【问题标题】:Magento top level Category listMagento 顶级类别列表
【发布时间】:2015-12-14 16:46:46
【问题描述】:

我需要在 Magento 1.9 网站中创建一个类别轮播。如何通过 PHP 获取顶级类别列表?

【问题讨论】:

    标签: list magento categories


    【解决方案1】:

    这应该会为您提供顶级类别列表

    $categories = Mage::getModel('catalog/category')->getCollection()
      ->addAttributeToSelect('*')//or you can just add some attributes
      ->addAttributeToFilter('level', 2)//2 is actually the first level, default is 1
      ->addAttributeToFilter('is_active', 1)//if you want only active categories
    ;
    

    现在转到foreach$categories 并以某种方式打印以使其成为轮播。

    【讨论】:

    • 感谢您的回复,我实际上结合了您的回复和@fschmengler 回复,现在我可以获得一系列类别,非常感谢! :)
    【解决方案2】:

    要获取当前商店的顶级类别,请查找商店根类别的所有直接子项:

    $rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
    $rootCategory = Mage::getModel('catalog/category')->load($rootCategoryId);
    $topLevelCategories = $rootCategory->getChildrenCategories();
    

    $topLevelCategories 现在是活动顶级类别的集合。

    【讨论】:

    • 感谢您的回复,我实际上使用了您和@K.C. 的组合。回复,我现在可以获得一系列类别,非常感谢! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-24
    • 1970-01-01
    相关资源
    最近更新 更多