对于菜单,如果想显示菜单,下面是直接改动源代码的方式实现的,当然在系统升级的时候有可能代码麻烦,完美方式当然是重写这个类,下面介绍的直接改动系统代码:
1
由page.xml得出
<block type="core/text_list" name="top.menu" as="topMenu"/>
type="core/text_list"得出,这个只是一个容器,类似于left,content等。
2
有catelog.xml得出
<reference name="top.menu">
<block type="catalog/navigation" name="catalog.topnav" template="catalog/navigation/top.phtml"/>
</reference>
故生成菜单的block
type为catalog/navigation
template为catalog/navigation/top.phtml
3
在navigation.php中加入方法,如下:
public function drawImgItem($category, $level=0, $last=false){
$html ="";
$categoryName = '';
if (!$category->getIsActive()) {
return $html;
}
$children = $category->getChildren();
$hasChildren = $children && $children->count();
$html.= '<li';
if ($hasChildren) {
$html.= ' οnmοuseοver="toggleMenu(this,1)" οnmοuseοut="toggleMenu(this,0)"';
}
$html.= ' class="level'.$level;
$html.= ' nav-'.str_replace('/', '-', $category->getRequestPath());
if ($this->isCategoryActive($category)) {
$html.= ' active';
}
if ($last) {
$html .= ' last';
}
if ($hasChildren) {
$cnt = 0;
foreach ($children as $child) {
if ($child->getIsActive()) {
$cnt++;
}
}
$html .= ' parent';
}
$html.= '">';
$categoryName = $category->getName();
$categoryName = htmlentities($categoryName, ENT_NOQUOTES, 'utf-8');
$categoryName = preg_replace('#&([A-za-z])(?:uml|circ|tilde|acute|grave|cedil|ring);#', '1', $categoryName);
$categoryName = preg_replace('#&([A-za-z]{2})(?:lig);#', '1', $categoryName);
$categoryName = preg_replace('#&[^;]+;#', '', $categoryName);
$url = Mage::getDesign()->getSkinUrl('images/'.strtolower(str_replace(" ","_",$categoryName)).'.jpg');
$html.= '<a href="'.$this->getCategoryUrl($category).'"><span>'.$this->htmlEscape($category->getName()).'</span><span><img src="'.$url.'"></span></a>';
if ($hasChildren){
$j = 0;
$htmlChildren = '';
foreach ($children as $child) {
if ($child->getIsActive()) {
$htmlChildren.= $this->drawImgItem($child, $level+1, ++$j >= $cnt);
}
}
if (!empty($htmlChildren)) {
$html.= '<ul class="level' . $level . '">'
.$htmlChildren
.'</ul>';
}
}
$html.= '</li>';
return $html;
}
4
修改
template/catalog/navigation/top.phtml
为:
<div class=”header-nav-container”>
<div class="header-nav">
<h4 class="no-display"><?php echo $this->__('Category Navigation:') ?></h4>
<ul id="nav">
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php echo $this->drawImgItem($_category) ?>
<?php endforeach ?>
</ul>
</div>
<?php echo $this->getChildHtml('topLeftLinks') ?>
</div>
5
在对应路径skin--->images/添加图片
由
$url = Mage::getDesign()->getSkinUrl('images/'.strtolower(str_replace(" ","_",$categoryName)).'.jpg');
得出,添加的图片的名字要和目录的名字一样,而且是jpg格式,当然你可以修改,然后添加在images/自己命名的文件夹/对用图片。
6
刷新缓存,目录图片出来了
!!!!!!