Magento导航块问题

时间:2014-04-18 03:12:36

标签: magento navigation categories

如何在主导航栏(左栏)中始终将子类别设置为可见?一旦我开始浏览任何类别的子类别,导航块仅显示顶级类别。例如www.valikoi.com。

问候,Tommi

1 个答案:

答案 0 :(得分:0)

我认为这会对你有帮助,

<ul class="catlist">
<?php
$obj = new Mage_Catalog_Block_Navigation();
$store_cats = $obj->getStoreCategories();
$current_cat    = $obj->getCurrentCategory();

$current_cat    = (is_object($current_cat) ? $current_cat->getName() : '');
$currentCategory = Mage::registry('current_category'); 

foreach ($store_cats as $cat) {
if ($cat->getName() == $current_cat) {
//enters and lists all main categories
echo '<li class="current">
<a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a>\n<ul>\n";

//get the child category of a current category  
 foreach ($obj->getCurrentChildCategories() as $subcat) {
echo '<li>
<a  href="'.$this->getCategoryUrl($subcat).'">'.$subcat->getName()."</a></li>\n";
}
echo "</ul>\n</li>\n";
} else {
//enters when a sub category is clicked and lists all main categories
echo '<li>
<a  href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."      </a></li>\n";

//this is to load the categories like in admin order
$loadCategory= Mage::getModel('catalog/category')->getCategories($currentCategory->getParentId(),0, true, true);

//below code did not work to load categories like in admin order
//$explod= $loadCategory->getChildrenCategories('position','asc');
//$subCategories = explode(',', $explod);

if (($currentCategory->getParentId() == $cat->getId()) )
{ 
//enters when a sub category is clicked and loads its parent and show its subcategories
echo '<ul class="catlist_inner">';
foreach ($loadCategory as $subCategoryId)
{


if($subCategoryId->getIsActive())
{
echo '<li>
<a href="'.$subCategoryId->getURL().'">'.$subCategoryId->getName().'</a>       </li>';
}
}
echo '</ul>';
}
}
}
?>
</ul>