我使用下面描述的方法为我的CMS页面添加带有活动类的链接。问题是,当我单击任何一个链接时,它都会变为活动状态,但即使在单击了其他一些链接后,类仍然存在。因此,其余的链接不会获得活动的类,而只会获得第一个打开的类。你知道问题出在哪里吗?
<li class="level0 nav-2 parent <?php if (strpos(Mage::helper('core/url')->getCurrentUrl(),'custom') != false ) :?> active<?php endif;?>">
<a href="<?php echo $this->getUrl('') . 'custom' ?>"><?php echo $this->__('TEXT OF MY LINK 1') ?></a>
</li>
<li class="level0 nav-3 parent <?php if (strpos(Mage::helper('core/url')->getCurrentUrl(),'wholesale') != false ) :?> active<?php endif;?>">
<a href="<?php echo $this->getUrl('') . 'wholesale' ?>"><?php echo $this->__('TEXT OF MY LINK 2') ?></a>
</li>
<li class="level0 nav-4 parent <?php if (strpos(Mage::helper('core/url')->getCurrentUrl(),'faq') != false ) :?> active<?php endif;?>">
<a href="<?php echo $this->getUrl('') . 'faq' ?>"><?php echo $this->__('TEXT OF MY LINK 3') ?></a>
</li>发布于 2013-10-17 15:25:56
尝试更改:
if (strpos(Mage::helper('core/url')->getCurrentUrl(),'custom') != false )至
if (strpos(Mage::helper('core/url')->getCurrentUrl(),'custom') !== false )或者,您可以获取当前CMS页面标识符并进行相应的检查,如
$current_page = Mage::getSingleton('cms/page')->getIdentifier();
//and check & add class
<li class="level0 nav-2 parent <?php if($current_page == 'custom' ):?> active <?php endif;?>">
....发布于 2013-10-17 18:08:41
你可以直接使用下面的代码来代替检查!=false。
<?php if (strpos(Mage::helper('core/url')->getCurrentUrl(),'custom')) :?> active<?php endif;?>更新后,从系统->缓存管理中清除Magento Admin中的所有缓存
或更新的代码:
<?php if (Mage::getSingleton('cms/page')->getIdentifier() == 'custom') :?> active<?php endif;?>试试这个,霍普会帮上忙的!
https://stackoverflow.com/questions/19420549
复制相似问题