Reputation: 55
Ok so i made my own theme and i used this code for my menu:
function the_nav_menu() {
$menu_name = 'nav-primary';
if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name])) {
$menu = wp_get_nav_menu_object($locations[$menu_name]);
$menu_items = wp_get_nav_menu_items($menu->term_id);
$current_item = 0;
foreach ((array) $menu_items as $key => $menu_item) {
$current_item++;
$title = $menu_item->title;
$url = $menu_item->url;
if($current_item == 3)
$menu_list .= "\t\t\t\t\t". '<li><a href="#!" class="dropdown-button" data-activates="dropdown-nav">'. $title .'<i class="material-icons right">arrow_drop_down</i></a><ul class="dropdown-content" id="dropdown-nav">' ."\n";
else
$menu_list .= "\t\t\t\t\t". '<li><a href="'. $url .'">'. $title .'</a></li>' ."\n";
}
} else {
// $menu_list = '<!-- no list defined -->';
}
echo $menu_list . '</ul></li>';
}
When i try to use that menu in the header.php i get the following error:
Notice: Undefined variable: menu_list in /home/u191493746/public_html/wp-content/themes/startedu/functions.php on line 56
Any ideeas?
Upvotes: 0
Views: 342
Reputation: 2008
before if inizialize $menu_list="";
function the_nav_menu() {
$menu_name = 'nav-primary';
$menu_list="";
if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name])) {
$menu = wp_get_nav_menu_object($locations[$menu_name]);
$menu_items = wp_get_nav_menu_items($menu->term_id);
$current_item = 0;
foreach ((array) $menu_items as $key => $menu_item) {
$current_item++;
$title = $menu_item->title;
$url = $menu_item->url;
if($current_item == 3)
$menu_list .= "\t\t\t\t\t". '<li><a href="#!" class="dropdown-button" data-activates="dropdown-nav">'. $title .'<i class="material-icons right">arrow_drop_down</i></a><ul class="dropdown-content" id="dropdown-nav">' ."\n";
else
$menu_list .= "\t\t\t\t\t". '<li><a href="'. $url .'">'. $title .'</a></li>' ."\n";
}
} else {
// $menu_list = '<!-- no list defined -->';
}
echo $menu_list . '</ul></li>';
}
Upvotes: 1