2012-11-08 115 views
0

前一段時間,我在此站點上設置了左側導航:http://makethemostof.co.uk/,以顯示頂級類別中的所有子類別,並顯示子類別中的所有兄弟類別。顯示父類別兒童的列表

我現在想要添加分層導航到子類別(但不是父類別)。分層導航工作正常,但我的代碼顯示兄弟類別不再起作用。請看這裏:http://makethemostof.co.uk/house-garden/kitchen父母('房子和花園')中可以找到的列表應該出現在過濾器的上方,但它不是。

這是我在佈局/的catalog.xml:

<catalog_category_layered translate="label"> 
    <label>Catalog Category (Anchor)</label> 
    <reference name="root"> 
     <action method="setTemplate"><template>page/2columns-left.phtml</template></action> 
    </reference> 
    <reference name="left"> 
     <block type="catalog/navigation" name="catalog.leftnav" template="catalog/navigation/left.phtml"/> 
     <block type="mana_filters/view_category" name="mana.catalog.leftnav" template="catalog/layer/view.phtml"/> 
     <!--<block type="catalog/layer_view" name="catalog.filters" template="catalog/layer/view.phtml"/>--> 
    </reference> 
    <reference name="content"> 
     <block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml"> 
      <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml"> 
       <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml"> 
        <block type="page/html_pager" name="product_list_toolbar_pager"/> 
       </block> 
       <action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action> 
       <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action> 
       <action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action> 
       <action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action> 
       <action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action> 
       <action method="setToolbarBlockName"><name>product_list_toolbar</name></action> 
      </block> 
     </block> 
    </reference> 
</catalog_category_layered> 

這裏是我的模板/目錄/導航/ left.phtml:

<?php $currentCat = Mage::registry('current_category'); 

if ($currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId()) { 
    echo '<h2 class="grad">'.$this->getCurrentCategory()->getName().'</h2>'; 
    $loadCategory = $currentCat; 
} else { 
    echo '<h2 class="grad"><a href="'.$this->getCurrentCategory()->getParentCategory()-  >getURL().'">'.$this->getCurrentCategory()->getParentCategory()->getName().'</a></h2>'; 
    $loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId()); 
} 

$cats = $loadCategory->getChildrenCategories(); ?> 

<ul> 
<?php foreach($cats as $category): ?> 
<? $category->load(); 
if ($category->getIsActive() && $category->getIncludeInMenu()) { ?> 
<li> 
    <a href="<?php echo $category->getUrl() ?>"><?php echo $category->getName() ?></a> 
</li> 
<? } ?> 

我只能假設在上面的某個地方有錯誤。任何幫助確定它將非常感激。謝謝!

回答

0

原來,這個問題是不是與模板文件,但與佈局。在catalog.xml放到位後,一個擴展是刪除左側導航塊,因此對catalog.xml的更改沒有任何影響。

1

試試這個

<?php 
    $currentCat = Mage::registry('current_category'); 

    if ($currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId()) { 
     echo '<h2 class="grad">'.$this->getCurrentCategory()->getName().'</h2>'; 
     $loadCategory = $currentCat; 
    } else { 
     echo '<h2 class="grad"><a href="'.$this->getCurrentCategory()->getParentCategory()->getURL().'">'.$this->getCurrentCategory()->getParentCategory()->getName().'</a></h2>'; 
     $loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId()); 
    } 
?> 


<ul> 
    <?php foreach($loadCategory->getChildrenCategories() as $subcategory): ?> 
     <?php if ($subcategory->getIsActive()) : ?> 
      <li> 
       <a href="<?php echo $subcategory->getUrl(); ?>"><?php echo $subcategory->getName(); ?></a> 
      </li> 
     <?php endif; ?> 
    <?php endforeach; ?> 
</ul> 

如果你有測試getIncludeInMenu()那麼你必須裝載每個類別

<ul> 
    <?php foreach($loadCategory->getChildrenCategories() as $subcategory): ?> 
    <?php $category = Mage::getModel('catalog/category')->load($subcategory->getId()); ?> 
     <?php if ($category->getIsActive() && $category->getIncludeInMenu()) : ?> 
      <li> 
       <a href="<?php echo $category->getUrl(); ?>"><?php echo $category->getName(); ?></a> 
      </li> 
     <?php endif; ?> 
    <?php endforeach; ?> 
</ul> 
+0

感謝您嘗試R.S! - 不幸的是,這隻意味着至少工作的父類別原來不起作用。請有更多想法嗎? –

+0

我剛剛更新了我的代碼和工作副本 –

+0

感謝R.S--這會更好,但恐怕導航仍然隱藏在錨點類別中。 –