magento-如何只设置与当前页面相关的按下/活动菜单项的样式


magento - how to style only the pressed/active menu item related to the current page we are in?

我只想在magento中突出显示按下的菜单项,可以吗?

我尝试过很多方法来实现这一点,但都没有成功(如果有帮助的话,我可以在这里列出一些)

谢谢

我尝试了php获取url,并将其与写在标签中的文本进行比较

2个尝试过的内置方法/id特定于magento

我已经取得了一些进展-我将此代码添加到我的模板文件-2columns-left.html中

    <?php
        $routeName = Mage::app()->getRequest()->getRouteName();
         echo $routeName;
       $body_class = $this->getLayout()->getBlock('root')->getBodyClass();
        echo $body_class;
        if(strpos(strtolower($body_class),strtolower($routeName)) !== false){
         $nav_active =  "class = 'nav_active'";
         }
        ?>

现在我已经在同一个文件中的body标签中添加了$nav_active,我尝试过了,但它不起作用

<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?><?php if(strpos(strtolower($body_class),strtolower($routeName)) !== false):?> echo $nav_active  ;?>>

您可以尝试使用我的替代解决方案

它在我这边工作

就像这个一样

 <?php if (strpos(Mage::helper('core/url')->getCurrentUrl(),'your_category_name') != false ) :?> active<?php endif;?>

希望这对你有帮助。