Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Update to fix PHP errors when no submenu exists
Browse files Browse the repository at this point in the history
  • Loading branch information
jmr06005 committed Nov 18, 2014
1 parent 938d11e commit 03aefd4
Showing 1 changed file with 38 additions and 36 deletions.
74 changes: 38 additions & 36 deletions inc/submenu-check.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
<?php
$has_sub_menu = false;
$menu_name = 'primary';
$current_id = 0;
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);
$level = 0;
$stack = array('0');
foreach($menu_items as $key => $menu_item) {
if($menu_item->object_id == get_the_ID()) $current_id = $menu_item->ID;
}
foreach($menu_items as $key => $menu_item) {
while($menu_item->menu_item_parent != array_pop($stack)) {
$level--;
}
$level++;
$stack[] = $menu_item->menu_item_parent;
$stack[] = $menu_item->ID;
$menu_items[$key]->level = $level;
if($menu_item->menu_item_parent == $current_id && $level > 2 || $menu_item->ID == $current_id && $level > 2){
$has_sub_menu = true;
}
}
//print_r($menu_items);
}
if($has_sub_menu){
?>

<div class="row">
<div class="col-sm-3">
<nav id="nav-secondary">
<?php include('sidemenu-walker.php')?>
</nav>
</div>
<div class="col-sm-8 col-sm-offset-1">
<?php
$has_sub_menu = false;
$menu_name = 'primary';
$current_id = 0;
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);
$level = 0;
$stack = array('0');
if(is_array($menu_items)){
foreach($menu_items as $key => $menu_item) {
if($menu_item->object_id == get_the_ID()) $current_id = $menu_item->ID;
}
foreach($menu_items as $key => $menu_item) {
while($menu_item->menu_item_parent != array_pop($stack)) {
$level--;
}
$level++;
$stack[] = $menu_item->menu_item_parent;
$stack[] = $menu_item->ID;
$menu_items[$key]->level = $level;
if($menu_item->menu_item_parent == $current_id && $level > 2 || $menu_item->ID == $current_id && $level > 2){
$has_sub_menu = true;
}
}
}
//print_r($menu_items);
}
if($has_sub_menu){
?>

<div class="row">
<div class="col-sm-3">
<nav id="nav-secondary">
<?php include('sidemenu-walker.php')?>
</nav>
</div>
<div class="col-sm-8 col-sm-offset-1">
<?php } /* end checkMenu */?>

0 comments on commit 03aefd4

Please sign in to comment.