Created
September 11, 2013 08:40
-
-
Save taion809/6520897 to your computer and use it in GitHub Desktop.
flat nested set to bootstrap 2.3 nested menu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $current_depth = 1; | |
| $html = ''; | |
| foreach($menu as $key => $value) | |
| { | |
| if(isset($menu[$key+1]) && $menu[$key+1]->DEPTH > $current_depth) | |
| { | |
| if($current_depth > 1) | |
| { | |
| $html .= "<li class='dropdown-submenu'>" . "\n"; | |
| $html .= '<a tabindex="-1" href="#">'.$value->title.' </a>' . "\n"; | |
| } | |
| else | |
| { | |
| $html .= "<li class='dropdown'>" . "\n"; | |
| $html .= '<a class="dropdown-toggle" data-toggle="dropdown" href="#">'.$value->title.' <b class="caret"></b></a>' . "\n"; | |
| } | |
| $html .= '<ul class="dropdown-menu">' . "\n"; | |
| ++$current_depth; | |
| continue; | |
| } | |
| elseif($value->DEPTH < $current_depth) | |
| { | |
| $html .= '</ul>' . "\n"; | |
| $html .= "</li>" . "\n"; | |
| --$current_depth; | |
| } | |
| if($value->type_title == 'link') | |
| { | |
| $html .= '<li><a href="'.$value->url.'">'.$value->title.'</a></li>' . "\n"; | |
| } | |
| elseif($value->type_title == 'separator') | |
| { | |
| $html .= '<li class="divider"></li>' . "\n"; | |
| } | |
| } | |
| echo $html; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment