Reputation: 967
A while ago I set up the left navigation on this site: http://makethemostof.co.uk/ to display all child categories when on a top level category and to display all the sibling categories when on a child category.
I now want to add layered navigation to the child categories (but not the parent categories). The layered navigation works fine but my code for displaying the sibling categories no longer works. Please see here: http://makethemostof.co.uk/house-garden/kitchen The list that can be found in the parent ('house and garden') should be appearing above the filters but it is not.
This is what I have in layout/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>
And here is what I have in template/catalog/navigation/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>
<? } ?>
I can only assume that there is an error somewhere in the above. Any help identifying it would be really appreciated. Thanks!
Upvotes: 0
Views: 981
Reputation: 967
It turned out that the issue was not with the template file but with the layout. An extension was removing the left navigation block after catalog.xml was putting it in place so changes to my catalog.xml had no effect.
Upvotes: 0
Reputation: 17656
Try this
<?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>
If you have to test for getIncludeInMenu()
then you have to load each category
<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>
Upvotes: 1