【问题标题】:Magento: get desription and image of child categoryMagento:获取子类别的描述和图像
【发布时间】:2012-09-19 21:55:16
【问题描述】:

我正在使用此代码在 Magento 中显示特定类别的子类别:

$parentCategoryId = 3;
foreach Mage::getModel('catalog/category')->load($parentCategoryId)->getChildrenCategories() as $childCategory) {
     echo $childCategory->getName() . '<br />';
     echo $childCategory->getUrl() . '<br />';
} 

这很好用。但现在我喜欢显示这些子类别的描述和类别图像。我已经尝试了描述并添加了这一行:

echo $childCategory->getDescription() . '<br />';

但是输出是空的。有谁知道我可以做些什么来显示描述和稍后的类别图片?

感谢您的帮助。

【问题讨论】:

    标签: magento


    【解决方案1】:

    请试试这个,它在我的最后工作正常

    <?php  
    $parentCategoryId = 10;
    $categories = Mage::getModel('catalog/category')->load($parentCategoryId)->getChildren();
    $catArray = explode(',', $categories);
    foreach($catArray as $child){
         $_child = Mage::getModel( 'catalog/category' )->load( $child );
         echo $_child->getName() . '<br />';
         echo $_child->getUrl() . '<br />';
         echo $_child->getDescription() . '<br />';
    }
    ?>
    

    我们不会从这个函数 getChildrenCategories() 中获取类别描述属性。关于这个函数的更好解释可以在这里找到Stackoverflow answer

    【讨论】:

    • 在 foreach 循环中加载模型是个坏主意,这会增加加载时间。它可能只适用于几张图片,但不适用于很多类别。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-27
    • 1970-01-01
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    相关资源
    最近更新 更多