我想将类别图像添加到我使用下面的代码检索的当前子类别列表中。
我怎么能这样做?
<?php
$i=0;
$count=1;
echo '<div class="empty-row">';
$_categories = $this->getCurrentChildCategories();
foreach($_categories as $_category):
{
if($i %3 ==0)
{ ?>
</div>
<div class="row">
<div class="item <?php if($count > 6) echo 'nobg'; ?>">
<h2><a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?> »</a></h2>
</div>
<? }
else
{ ?>
<div class="item <?php if($count > 6) echo 'nobg'; ?>">
<h2><a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?> »</a></h2>
</div>
<? }
$i++;
}
$count++; endforeach;
?>
答案 0 :(得分:2)
以下是带图片的获取子类别,如果您想获得根类别,只需修改代码即可。
<?php
$layer = Mage::getSingleton('catalog/layer');
$_category = $layer->getCurrentCategory();
$_categories = $_category->getCollection()->addAttributeToSelect(array('url_key','name','image','all_children','is_anchor','description'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($_category->getChildren())
->setOrder('position', 'ASC')
->joinUrlRewrite();
?>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()): ?>
<img src="<?php echo $this->htmlEscape($_category->getImageUrl()) ?>" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" />
<a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?></a>
<?php endif; ?>
<?php endforeach; ?>