-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-bootstrap-navmenu.php
112 lines (110 loc) · 4.91 KB
/
wp-bootstrap-navmenu.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/*
Plugin Name: WP Bootstrap Menu
Version: 1.1.0
Description: Convert Wordpress nav menu to Twitter Bootstrap style.
Plugin URI: http://wordpress.org/extend/plugins/wp-bootstrap-navmenu/
Author: Sajjad Rad
Author URI: http://sajjadrad.com/
*/
$plugin_dir = plugin_basename(__FILE__);
function getNavMenu($menuName,$dropDownOption = "click")
{
$menu = $menuName; //Nav menu name
$items = wp_get_nav_menu_items($menu); // Get nav menu items list
$level = 0;
$last_title = "";
$last_url = "";
$objectID_stack = array();
$objectIDStackTop = 0;
$output = "";
foreach ($items as $list)
{
if($list->menu_item_parent == "0")
{
while(count($objectID_stack))
{
array_pop($objectID_stack);
}
if($level == 1)
{
$output = $output."<li><a href=\"".$last_url."\">".$last_title."</a></li>";
}
if($level == 3)
{
$output = $output."<li><a href=\"".$last_url."\">".$last_title."</a></li></ul></li></ul></li>";
}
if($level == 2)
{
$output = $output."<li><a href=\"".$last_url."\">".$last_title."</a></li></ul></li>";
}
$level = 1 ;
array_push($objectID_stack, $list->object_id);
$last_title = $list->title;
$last_url = $list->url;
}
else
{
$stackTop = count($objectID_stack)-1;
if($list->menu_item_parent == $objectID_stack[$stackTop])
{
if($level == 1)
{
if($dropDownOption == "click")
$output = $output."<li class=\"dropdown\"><a class=\"dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\">".$last_title."<b class=\"caret\"></b></a><ul class=\"dropdown-menu\">";
else
$output = $output."<li class=\"dropdown\"><a class=\"dropdown-toggle\" data-toggle=\"dropdown\" href=\"".$last_url."\">".$last_title."<b class=\"caret\"></b></a><ul class=\"dropdown-menu\">";
$last_title = $list->title;
$last_url = $list->url;
$level = 2;
array_push($objectID_stack, $list->object_id);
}
else if ($level == 2)
{
if($dropDownOption == "click")
$output = $output."<li class=\"dropdown-submenu\"><a href=\"#\">".$last_title."</a><ul class=\"dropdown-menu sub-menu\">";
else
$output = $output."<li class=\"dropdown-submenu\"><a href=\"".$last_url."\">".$last_title."</a><ul class=\"dropdown-menu sub-menu\">";
$last_title = $list->title;
$last_url = $list->url;
$level = 3;
}
else if($level == 3)
{
$output = $output."<li><a href=\"".$last_url."\">".$last_title."</a></li>";
$last_title = $list->title;
$last_url = $list->url;
$level = 3;
}
}
else
{
if($level == 2)
{
array_pop($objectID_stack);
$output = $output."<li><a href=\"".$last_url."\">".$last_title."</a></li>";
$last_title = $list->title;
$last_url = $list->url;
$level = 2;
array_push($objectID_stack, $list->object_id);
}
if($level == 3)
{
array_pop($objectID_stack);
$output = $output."<li><a href=\"".$last_url."\">".$last_title."</a></li></ul></li>";
$last_title = $list->title;
$last_url = $list->url;
$level = 2;
array_push($objectID_stack, $list->object_id);
}
}
}
}
if($level == 1) //If is parent and not printed.
$output = $output."<li><a href=\"".$last_url."\">".$last_title."</a></li>";
else if($level == 2) //If is sub and not printed.
$output = $output."<li><a href=\"".$last_url."\">".$last_title."</a></li></ul></li>";
else if($level == 3) //If is sub of sub and not printed.
$output = $output."<li><a href=\"".$last_url."\">".$last_title."</a></li></ul></li></ul></li>";
return $output;
}