我正在使用下面的代码来获取与当前页面处于同一级别的类别列表(通过列出该类别的父类别的子类别)。平面类别关闭时效果很好。启用平面类别后,H2 可以正常工作,但列表会更改为显示根的子类别,而不是此页面的父级子类别。我做错了什么,为什么会这样?
<?php
$_category = $this->getCurrentCategory();
$parentCategoryId = $_category->getParentId();
$collection = Mage::getModel('catalog/category')->getCategories($parentCategoryId);
$helper = Mage::helper('catalog/category');
$parentCategory = Mage::getModel('catalog/category')->load($parentCategoryId);
?>
<h2><?php echo $parentCategory->getName(); ?></h2>
<ul>
<?php foreach ($collection as $cat):?>
<?php if($_category->getIsActive()): ?>
<li <?php
if ($cat->getId() == $_category->getId()) {
echo 'class="current"';
}
?>>
<a href="<?php echo $helper->getCategoryUrl($cat);?>"><?php echo $cat->getName();?></a>
</li>
<?php endif; ?>
<?php endforeach;?>
</ul>
是的,我已经刷新了缓存和索引。