Php 从Magento中的子类别列表中获取名称和图像
我正在尝试获取Magento类别的所有子类别,并显示它们的名称和图像 到目前为止,我已经:Php 从Magento中的子类别列表中获取名称和图像,php,magento,magento-1.7,Php,Magento,Magento 1.7,我正在尝试获取Magento类别的所有子类别,并显示它们的名称和图像 到目前为止,我已经: $children = Mage::getModel('catalog/category')->getCategories(28); foreach ($children as $category) { echo "name: " . $category->getName() . "<br>"; echo "image: " . $category->ge
$children = Mage::getModel('catalog/category')->getCategories(28);
foreach ($children as $category) {
echo "name: " . $category->getName() . "<br>";
echo "image: " . $category->getImageUrl() . "<br>";
}
$children=Mage::getModel('catalog/category')->getCategories(28);
foreach($children作为$category){
echo“name:”.$category->getName().“
”;
回显“图像:”.$category->getImageUrl().“
”;
}
$category->getName()
有效,但$category->getImageUrl()
似乎不起作用
我遵循目录/类别模型的参考(请参见顶部的Mage:catalog,然后是侧面的Mage_catalog_model_catalog)
它清楚地表明,string getImageUrl()
是该类的一个可用方法,但是我显然不能调用它
我想知道为什么在上面的例子中这个方法不可用,更一般地说,为什么一个类中有很多方法似乎不可用,这样我就可以理解将来如何解决这些重复出现的问题
因此,我的问题是,上面需要什么才能使getImageUrl
方法可用,通常我如何确定需要添加什么才能使文档中的其他方法“默认”在Magento框架中不可用
任何帮助都将不胜感激。谢谢。试试看:-
<?php
//gets all sub categories of parent category
$cats = Mage::getModel('catalog/category')->load(6)->getChildren();
$catIds = explode(',',$cats);
$categories = array();
foreach($catIds as $catId) {
$category = Mage::getModel('catalog/category')->load($catId);
$categories[$category->getName()] = array(
'url' => $category->getUrl(),
'img' => $category->getImageUrl()
);
}
ksort($categories, SORT_STRING);
?>
<ul>
<?php foreach($categories as $name => $data): ?>
<li>
<a href="<?php echo $data['url']; ?>" title="<?php echo $name; ?>">
<img class="cat-image" src="<?php echo $data['img']; ?>" />
</a>
</li>
<?php endforeach; ?>
</ul>
-
您好,谢谢,这很有效。。。您知道有没有一种方法不需要从IDs字符串手动构建数组?我相信Magento有一种方法可以在一次调用中获取所有数据?。。。这也很有帮助,干杯。