我需要在左侧或右侧导航中显示类别和子类别,还需要在 Magento 中显示两个级别的类别。请给我提意见.....
例如:
categories
----sub1
---sub2
我需要在左侧或右侧导航中显示类别和子类别,还需要在 Magento 中显示两个级别的类别。请给我提意见.....
例如:
categories
----sub1
---sub2
在左侧栏中添加类别导航 -
在您的主题中创建新文件“categorymenu.phtml” - template\catalog\navigation\categorymenu.phtml
将以下代码放入其中 -
<div class="block block-category">
<div class="inside-box">
<div class="block-title block-category-title"><h2><?php echo $this->__('Categories') ?></h2></div>
<div class="block-category-navigation">
<ul id="category-nav">
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php if($_category->name!=""): ?>
<li><?php echo $this->drawItem($_category) ?></li>
<?php endif?>
<?php endforeach ?>
</ul>
</div>
</div>
</div>
然后在位于主题文件夹中的 catalog.xml 文件中调用它 -
主题\布局\catalog.xml。看起来像 :
<reference name="left">
<block type="catalog/navigation" name="catalog.categorymenu" after="top.search" template="catalog/navigation/categorymenu.phtml"/> <-- this is new block added by us -->
<block type="core/template" name="left.permanent.callout" template="callouts/left_col.phtml">
...
...
</reference>
转到布局 xml 文件夹...
/app/design/frontend/default/default/layout/catalog.xml
打开 catalog.xml 并粘贴它...
<reference name="left">
<block type="catalog/navigation" name="catalog.leftnav" template="catalog/navigation/left_nav.phtml" />
</reference>
进一步修改了.phtml文件..
<?php
$obj = new Mage_Catalog_Block_Navigation();
$store_cats = $obj->getStoreCategories();
$current_cat = $obj->getCurrentCategory();
$current_cat = (is_object($current_cat) ? $current_cat->getName() : '');
foreach ($store_cats as $cat) {
if ($cat->getName() == $current_cat) {
echo '<li class="current"><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a>\n<ul>\n";
foreach ($obj->getCurrentChildCategories() as $subcat) {
echo '<li><a href="'.$this->getCategoryUrl($subcat).'">'.$subcat->getName()."</a></li>\n";
}
echo "</ul>\n</li>\n";
} else {
echo '<li><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a></li>\n";
}
}
?>
现在刷新缓存和重新索引过程......