dongliang1865 2014-05-28 01:58
浏览 152
已采纳

如何将活动的css类添加到Wordpress中的链接

how to add active css class to a link in Wordpress such that the active menu li will have different color when that link is viewed.

<ul>
  <li class=""><a href="/news">News</a></li> 
  <li class="devider">&nbsp;</li>
  <li class=""><a href="/about">About Us</a></li> 
  <li class="devider">&nbsp;</li>
  <li><a href="#">Partners</a></li> 
  <li class="devider">&nbsp;</li> 
  <li><a href="/vacancy">Careers</a></li>  <li class="devider">&nbsp;</li>
  <li><a target="_blank" href="/webmail">Email Login</a></li>
</ul>
  • 写回答

2条回答 默认 最新

  • dongyou5271 2014-05-30 17:45
    关注

    This is the most simple way to solve it. No javascript or anything than just Wordpress

    Use it just using Wordpress built-in boolean function

     <li<?php if (is_page('services')) { echo ' class="current_page_item"'; } ?>><a href="<?php echo home_url();?>/services">Services</a></li>
    

    here is the link from where i got this idea. http://www.vanseodesign.com/wordpress/hightlight-current-page-wordpress/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?