2012-12-07 88 views

回答

2

要在左側欄添加類別導航 -

創建新文件在主題爲 「categorymenu.phtml」 - 模板\目錄\導航\ 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> 
+1

謝謝你Tejas .......其工作.............. –

1

去佈局的xml文件夾...

/應用程序/設計/前端/預設/默認/佈局/目錄.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"; 
    } 
} 
?> 

現在刷新緩存和重新索引過程....

+2

我的答案是什麼.....是否正確? – 2012-12-14 14:08:50

+0

這一個爲我工作 – AdRock