Add class=“active” to active page using PHP

前端 未结 10 765
你的背包
你的背包 2020-12-01 06:47

Dynamic Header, CSS Class Change To Active USING PHP (dirrectory)

I want the class of the

  • tag to change under the active dirrectory... now
  • 10条回答
    •  小蘑菇
      小蘑菇 (楼主)
      2020-12-01 07:40

      It's probably easier to do with jQuery but this works:

      $url='http://example.com/tutorials/css/flawless-dropdown-menu';//pass the current url here instead of a static string.
      $segments = explode ("/",$url);
      
      $menuItems=array('Tutorials','Resources', 'Library', 'Our-Projects','Community');
      
      
      $menu=array();
      foreach ($menuItems as $menuItem) {
      if($segments[3]==strtolower($menuItem)){
          $menu[]=('
    • '.str_replace("-"," ",$menuItem).'
    • '); } else { $menu[]=('
    • '.str_replace("-"," ",$menuItem).'
    • '); } } foreach ($menu as $item) { echo $item.'
      '; }

    提交回复
    热议问题