我正在为magento的侧栏工作,显示子类别
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 :(得分: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();
答案 1 :(得分:0)
最简单的解决方案是比较当前网址是否包含类别名称或类别网址密钥。然后将其设置为活动状态。