2014-04-24 83 views
0

我正在一个侧栏的Magento的显示子类别如何设置活动类到php生成的链接?

echo '<div id="sidenavcat">'; 
$object = new Mage_Catalog_Block_Navigation(); 
$actualCategoryId = $object->getCurrentCategory()->getId(); 
$actualCategory = Mage::getModel('catalog/category')->load($actualCategoryId); 
$subCategories = explode(',', $actualCategory->getChildren()); 

foreach ($subCategories as $subCategoryId) 
{ 
    $category = Mage::getModel('catalog/category')->load($subCategoryId); 
    if ($category->getIsActive()) 
    { 
echo '<li><a href="'.$category->getURL().'" style="text-decoration: none"   class="active">'.$category->getName().'</a> </li>'; 
    } 
} 
echo '</div>'; 

我怎么会去加入活性类的各路段上?

回答

0

只需要设置其他部分

foreach ($subCategories as $subCategoryId) 
{ 
    $category = Mage::getModel('catalog/category')->load($subCategoryId); 
    if ($category->getIsActive()) 
    { 
echo '<li><a href="'.$category->getURL().'" style="text-decoration: none"   class="active">'.$category->getName().'</a> </li>'; 
    }else{ 

echo '<li>'.$category->getName().' </li>'; 
} 
} 

如果你想目前的类别,然后使用下面的代码

Mage::registry('current_category')->getId(); 
+0

getIsActive()会查看该类别是否处于活动状态。您的解决方案将只显示不活动的类别。 –

0

一个简单的办法是比较,如果当前的URL中包含类别的名称或类别url键也许。然后将其设置为活动状态。