不久之前,我在此网站上设置了左侧导航:http://makethemostof.co.uk/,以便在顶级类别上显示所有子类别,并在子级别上显示所有兄弟类别。
我现在想要为子类别添加分层导航(但不是父类别)。分层导航工作正常,但我显示兄弟类别的代码不再有效。请看这里:http://makethemostof.co.uk/house-garden/kitchen可以在父母('住宅和花园')中找到的列表应该出现在过滤器上方,但事实并非如此。
这就是我在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>
以下是我在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>
<? } ?>
我只能假设上面某处出现错误。任何帮助识别它将非常感激。谢谢!
答案 0 :(得分: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>
答案 1 :(得分:0)
事实证明问题不在于模板文件,而在于布局。扩展名是在catalog.xml将其放置到位后删除左侧导航块,因此对catalog.xml的更改无效。