php - active link to posts in pages Wordpress -


i have been reading around how make navigation link stay active, when inside post[ single page ]. haven't found solutions created mix of jquery , php, don't think right way dough work.

so thinking of how optimize code more. ides ?

<?php  if (in_category('news')){ ?>     <script>      $(".menu-item-46 a").css("border-bottom","#000 5px solid");      $(".menu-item-46 a").css("padding-bottom","11px");     </script> <?php }elseif (in_category('network')){ ?>     <script>      $(".menu-item-47 a").css("border-bottom","#000 5px solid");      $(".menu-item-47 a").css("padding-bottom","11px");     </script> <?php } ?> 

one way tackle problem take advantage of css.

have class called "active", , append parent element holding menu wish show.

example:

<div class="active">      <div class="menu-item-46"><a>my nav</a></div> </div> 

then in css file:

.active .menu-item-46{     border-bottom:#000 5px solid;     padding-bottom:11px; } 

another suggestion give menu items, generic class, "menu-item", id "menu-item-##". css can ".active .menu-item"


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -