function nav_item($nav_id, $text, $internal_uri, $options = array()) { $css_class = array(); // 'icon' option sets a class name on the LI tag instead of the link itself if (isset($options['icon'])) { array_push($css_class, $options['icon']); unset($options['icon']); } $active = nav_active($nav_id); if ($active) { $link = content_tag('span', $text, $options); } else { $link = link_to($text, $internal_uri, $options); } return '<li' . ($active ? ' class="active"' : '') . '>' . $link . '</li>'; }
function nav($menu_items, $child = false) { $output = ''; if (count($menu_items) > 0) { $output .= $child === false ? '<ul class="nav navbar-nav">' : '<ul class="dropdown-menu">'; foreach ($menu_items as $nav_item) { if (!empty($nav_item['target'])) { $nav_target = 'target="' . $nav_item['target'] . '"'; } else { $nav_target = ""; } if (strpos($nav_item['url'], "http://") !== false or strpos($nav_item['url'], "https://") !== false) { $nav_url = $nav_item['url']; } else { $nav_url = "" . BASE_URL . "" . $nav_item['url'] . ""; } //check if there are any children if (isset($nav_item['children']) && count($nav_item['children'])) { $children = 1; } else { $children = 0; } if ($children == 1) { $output .= '<li class="dropdown">'; $output .= '<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" href="' . $nav_url . '" ' . $nav_target . '>' . $nav_item['title'] . ' <span class="caret"></span></a>'; } else { $output .= '<li' . nav_active($nav_url) . '>'; $output .= '<a href="' . $nav_url . '" ' . $nav_target . '>' . $nav_item['title'] . '</a>'; } //loop if ($children == 1) { $output .= nav($nav_item['children'], true); } $output .= '</li>'; } $output .= '</ul>'; } return $output; }