-
-
Save josecarlospsh/95ca08dae2bbb0ad1067 to your computer and use it in GitHub Desktop.
Revisions
-
levymetal revised this gist
Apr 12, 2013 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ <?php function my_custom_submenu() { global $post; -
levymetal created this gist
Apr 12, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ function my_custom_submenu() { global $post; $menu_items = wp_get_nav_menu_items('Menu'); $current_menu_id = 0; // get current top level menu item id foreach ( $menu_items as $item ) { if ( $item->object_id == $post->ID ) { // if it's a top level page, set the current id as this page. if it's a subpage, set the current id as the parent $current_menu_id = ( $item->menu_item_parent ) ? $item->menu_item_parent : $item->ID; break; } } // display the submenu echo "<ul id='supplementary_menu'>"; foreach ( $menu_items as $item ) { if ( $item->menu_item_parent == $current_menu_id ) { $class = ( $item->object_id == $post->ID ) ? "class='current_page_item'" : ""; echo "<li {$class}><a href='{$item->url}'>{$item->title}</a>"; $sub_menu_items = []; foreach ( $menu_items as $sub_item ) { if ( $sub_item->menu_item_parent == $item->ID ) $sub_menu_items[] = $sub_item; } if ( $sub_menu_items ) { echo "<ul>"; foreach ( $sub_menu_items as $sub_item ) { $class = ( $sub_item->object_id == $post->ID ) ? "class='current_page_item'" : ""; echo "<li {$class}><a href='{$sub_item->url}'>{$sub_item->title}</a>"; } echo "</ul>"; } echo "</li>"; } } echo "</ul>"; }