2009-12-28 22 views
0

我在top.phtml这个代码显示在我的Magento商店我的菜单项:Magento的 - 删除活动状态从主页

<div class="header-nav-container"> 
<div class="header-nav"> 
<h4 class="no-display"><?php echo $this->__('Category Navigation:') ?></h4> 
<ul id="nav"> 
<li <?php if(!Mage::registry('current_category')) { echo 'class="level0 active"'; } else { echo 'class="level0"'; } ?>><a href="<?php echo $this->getUrl('') ?>"><span><?php echo $this->__('Home') ?></span></a></li> 
<?php foreach ($this->getStoreCategories() as $_category): ?> 

<?php echo $this->drawItem($_category) ?> 
<?php endforeach ?> 
<li <?php if(!Mage::registry('current_category')) { echo 'class="level0 active"'; } else { echo 'class="level0"'; } ?>><a href="<?php echo $this->getUrl('catalogsale')?>"><span><?php echo $this->__('Sale Items') ?></span></a></li> 
</ul> 

</div> 

我有一个额外的li在其中显示另一个页面底部。我点击“销售商品”页面时出现的问题:其链接变为活动状态,但主页链接也一样。如何防止主页链接显示为活动状态?

我添加了一个截图显示问题: Screenshot

回答

2

家庭和销售项目的线条都为没有定义的当前类别时主动类别链接,通过代码if(!Mage::registry('current_category'))。而不是检查类别,检查当前的控制器/操作。

这里的URL功能的列表(用于获取控制器/动作):

http://docs.magentocommerce.com/Mage_Core/Mage_Core_Model_Url.html

这样的代码应该工作。这取决于catalogsale是否是一个自定义控制器或行动,这取决于你的设置标识符:

if ($this->getRequest()->getControllerName() == 'catalogsale') 
// Output active class declaration 

/* Otherwise, try looking at the action name. */ 

if ($this->getRequest()->getActionName() == 'catalogsale') 
// Output active class declaration 
+0

我尝试了这两个但都没有工作。 – a1anm 2009-12-28 22:55:49

0

最后我用一些JavaScript解决这个。我将此添加到新页面:

<script type="text/javascript"> 
Event.observe(window, 'load', function() { 
$$('li.active').invoke('removeClassName','active'); 
$$('li.newmenu').invoke('addClassName','active'); 
}); 
</script> 

新的菜单项应该有一类'newmenu',以便上面的代码可以工作。

相关问题