我正在按父类别 ID 显示子类别列表,并且希望显示类别图像来代替类别名称。
这是我到目前为止...
<div id="menu_brands">
<div class="brand_head">
<h3><?php echo $this->__('Browse By Brand') ?></h3>
</div>
<div class="brand_list">
<?php
$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()] = $category->getUrl();
$img = $category->getImageUrl(); //I suspect this line is wrong
}
ksort($categories, SORT_STRING);
?>
<ul>
<?php foreach($categories as $name => $url): ?>
<li>
<!--<a href="<?php echo $url; ?>"><?php echo $name; ?></a>-->
<a href="<?php echo $url; ?>" title="<?php echo $name; ?>">
<img src="<?php echo $img; ?>" width="auto" alt="<?php echo $name; ?>" /> <!--I suspect this line is wrong-->
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
我尝试了无数种方法来显示图像来代替类别名称,但似乎没有任何东西可以使图像出现。目前使用上述内容,输出是一个空的“img src”,因此我正在尝试的内容显然存在错误(并且可能是实现我所追求的更好的方法)。
请有人能指出问题所在吗?
如果它有任何相关性,我打算之后做的是以网格格式(每行 3 或 4 个)显示类别图像。
提前谢谢了。