我是magento的新手,我需要一些帮助来显示该类别的图像, 我已经从我的magento后端上传了一个类别的图像,我试图在这样的导航栏中显示
<ul id="nav_category" class="nav_category">
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php echo Mage::getModel('catalog/category')->load($_category->getId())- >getImageUrl() ?>
<?php endforeach ?>
</ul>
但它没有显示图片网址,只是显示了drawItem函数中的类别名称。
请帮忙
感谢
答案 0 :(得分:0)
Vikash,请尝试以下代码......
<ul id="nav_category" class="nav_category">
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php
$_helper = Mage::helper('catalog/output');
$_imgHtml = '';
if ($_imgUrl = $_category->getImageUrl()) {
$_imgHtml = '<img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$_category->getName().'" />';
$_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
?>
<?php if($_imgUrl): ?>
<?php echo $_imgHtml ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
答案 1 :(得分:0)
是的,您可以在magento1.9的顶部导航菜单中显示类别图像: 步骤:
加载类别对象:
$category = Mage::getModel('catalog/category')->load('category-id');
然后调用getData()
方法:
$category->getData('image'); // It will return image url;
然后添加媒体目录路径:
Mage::getBaseUrl('media'); // returns megento media directory path.
以下是我使用过的示例代码。
$splittedArray = explode($delimiter = 'category-node-', $child->getId());
$category = Mage::getModel('catalog/category')->load(end($splittedArray));
if (!empty($category->getData('image'))) {
$html .= '<div> ';
$html .= "<a href=" . $category->getURL() . " title =" . $category->getName() . ">";
$html .= "<img src=" . Mage::getBaseUrl('media') . 'catalog/category/' . $category->getData('image') . " alt=" . $category->getName() . " >";
$html .= "</a>";
$html .= '</div>';
}