Magento - 在顶部类别菜单名称旁边放置一个图像


Magento - Put an image next to top category menu name

我想在我的每个类别和子类别名称旁边放一个小图像图标(不要用图像替换类别名称,只需在类别名称后面放置图像)。我已经尝试覆盖应用程序/核心/代码/法师/目录/块/导航.php

我更改了_renderCategoryMenuItemHtml之后在样式中引用category_id.css我即将在代码所在的位置添加背景图像

 $htmlLi .= '>';
$html[] = $htmlLi;
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';

$htmlLi .= '>';
$html[] = $htmlLi;
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
$html[] = '<span class="category_'.$this->getCurrentCategory()->getId().'">'.$this->escapeHtml($category->getName()).'</span>';
$html[] = '</a>';

但丁丁工作。我相信很多人可能想在类别名称后面显示一个小缩略图。但只是不知道任何简单或直接的方法。

任何帮助,不胜感激。谢谢。

为什么不使用CSS背景图像?

加载模板/目录/导航/top.phtml,并为每个关卡的<>项添加新的类或ID,可能是这样的:

class="nav-<?php echo $_category->getName() ?>"

然后将这些类添加到您的 CSS 中,即:

.nav-shoes { background: url(images/nav-shoes.png) no-repeat; }

或者更好的是,使用您想要使用的所有图像构建一个精灵图像:

[class^="nav-"] { background: url(images/sprite.png) no-repeat; }
.nav-shoes { background-position: 10px 10px; }

然后,您需要为每张图像找出背景位置。

将此解决方案用于 Magento -1.8。

转到 intp 模型文件。(/app/code/core/Mage/Catalog/Model/Observer.php)

在函数名称中:_addCategoriesToMenu

更新以下代码

  $categoryData = array( 
        'name' => $category->getName(),
        'id' => $nodeId,
        'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
        'is_active' => $this->_isActiveMenuCategory($category),
        'thumbnail' => Mage::getModel('catalog/category')->load($category->getId())->getThumbnail()
    );

然后进入 HTML 文件夹。(app/code/core/Mage/Page/Block/Html/Topmenu.php)

在函数名称中的第 128 行:_getHtml

更新以下代码行

    if($childLevel < 1 ){
        $urls = Mage::getBaseUrl('media').'catalog/category/'.$child->getData('thumbnail');
        $img = '<img src="'.$urls.'" />';
    }
    $html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>';
    $html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
        . $this->escapeHtml($child->getName()) . ' </span> '.$img.' </a>';