-
-
Save mjot/06cba267144a9716caf79c4ad4f2dce6 to your computer and use it in GitHub Desktop.
Revisions
-
mjot revised this gist
Nov 27, 2018 . 4 changed files with 47 additions and 63 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 @@ -0,0 +1,41 @@ function wecGenerateMenu($menu_name) { $menu = wp_get_nav_menu_object($menu_name); $locations = get_nav_menu_locations(); $menu = wp_get_nav_menu_object( $locations[ $menu_name ] ); $menuitems = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) ); $count = 0; $content_ = ""; $submenu = false; foreach($menuitems as $item){ $url = $item->url; $title = $item->title; $active = ( $item->object_id == get_queried_object_id() ) ? 'active' : ''; // Parent if (!$item->menu_item_parent){ $parent_id = $item->ID; $content_ .= '<li class="nav-item '.$active.'"><a class="nav-link" href="'.$url.'">'.$title.'</a>'; } // Child if ($parent_id == $item->menu_item_parent){ if (!$submenu ){ $submenu = true; } $content_ .= '<ul class="sub-menu"><li class="item"><a href="'.$url.'" class="title">'.$title.'</a></li>'; if (!isset($menuitems[ $count + 1 ]) || $menuitems[ $count + 1 ]->menu_item_parent != $parent_id && $submenu){ $content_ .= '</ul>'; $submenu = false; } } if (!isset($menuitems[ $count + 1 ]) || $menuitems[ $count + 1 ]->menu_item_parent != $parent_id){ $content_ .= '</li>'; $submenu = false; } $count++; } $content_ .= '</ul>'; return $content_; } 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,5 @@ <nav> <ul> <?php echo wecGenerateMenu('nav_main'); ?> </ul> </nav> 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,9 +1 @@ This gist is for showing an example of a custom wordpress menu. 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,54 +0,0 @@ -
hitautodestruct revised this gist
Mar 31, 2015 . 1 changed file with 3 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,6 +1,9 @@ This gist is for showing an example of a custom wordpress menu. If you want to get more from the menu item simply have a look at the $item object. i.e: // Will return a large object with lots of props like title, url, description, id etc. var_dump( $item ); This code works on Wordpress 4.1.1 as of 31st of March 2015 -
hitautodestruct revised this gist
Mar 31, 2015 . 1 changed file with 1 addition 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,5 +1,6 @@ If you want to get more from the menu item simply have a look at the $item object. i.e: // Will return a large object with lots of props like title, url, description, id etc. var_dump( $item ); -
hitautodestruct revised this gist
Mar 31, 2015 . 1 changed file with 1 addition and 2 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,6 +1,5 @@ If you want to get more from the menu item simply have a look at the $item object. i.e: // Will return a large object with lots of props like title, url, description, id etc. var_dump( $item ); -
hitautodestruct revised this gist
Mar 31, 2015 . 1 changed file with 2 additions and 2 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,6 +1,6 @@ If you want to get more from the menu item simply have a look at the $item object. i.e: ### Will return a large object with lots of props like title, url, description, id etc. var_dump( $item ); -
hitautodestruct revised this gist
Mar 31, 2015 . 1 changed file with 6 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 @@ -0,0 +1,6 @@ If you want to get more from the menu item simply have a look at the $item object. i.e: // Will return a large object with lots of props like title, url, description, id etc. var_dump( $item ); -
hitautodestruct renamed this gist
Mar 31, 2015 . 1 changed file with 4 additions and 11 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 @@ -12,12 +12,9 @@ $submenu = false; foreach( $menuitems as $item ): $link = $item->url; $title = $item->title; // item does not have a parent so menu_item_parent equals 0 (false) if ( !$item->menu_item_parent ): @@ -27,10 +24,7 @@ <li class="item"> <a href="<?php echo $link; ?>" class="title"> <?php echo $title; ?> </a> <?php endif; ?> @@ -41,8 +35,7 @@ <?php endif; ?> <li class="item"> <a href="<?php echo $link; ?>" class="title"><?php echo $title; ?></a> </li> <?php if ( $menuitems[ $count + 1 ]->menu_item_parent != $parent_id && $submenu ): ?> -
hitautodestruct revised this gist
Mar 28, 2013 . No changes.There are no files selected for viewing
-
hitautodestruct revised this gist
Dec 20, 2012 . 1 changed file with 4 additions and 1 deletion.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 @@ -55,4 +55,7 @@ </li> <?php $submenu = false; endif; ?> <?php $count++; endforeach; ?> </ul> </nav> -
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,58 @@ <?php $menu_name = 'main_nav'; $locations = get_nav_menu_locations(); $menu = wp_get_nav_menu_object( $locations[ $menu_name ] ); $menuitems = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) ); ?> <nav> <ul class="main-nav"> <?php $count = 0; $submenu = false; foreach( $menuitems as $item ): // get page id from using menu item object id $id = get_post_meta( $item->ID, '_menu_item_object_id', true ); // set up a page object to retrieve page data $page = get_page( $id ); $link = get_page_link( $id ); // item does not have a parent so menu_item_parent equals 0 (false) if ( !$item->menu_item_parent ): // save this id for later comparison with sub-menu items $parent_id = $item->ID; ?> <li class="item"> <a href="<?php echo $link; ?>" class="title"> <?php echo $page->post_title; ?> </a> <a href="<?php echo $link; ?>" class="desc"> <?php echo $page->post_excerpt; ?> </a> <?php endif; ?> <?php if ( $parent_id == $item->menu_item_parent ): ?> <?php if ( !$submenu ): $submenu = true; ?> <ul class="sub-menu"> <?php endif; ?> <li class="item"> <a href="<?php echo $link; ?>" class="title"><?php echo $page->post_title; ?></a> <a href="<?php echo $link; ?>" class="desc"><?php echo $page->post_excerpt; ?></a> </li> <?php if ( $menuitems[ $count + 1 ]->menu_item_parent != $parent_id && $submenu ): ?> </ul> <?php $submenu = false; endif; ?> <?php endif; ?> <?php if ( $menuitems[ $count + 1 ]->menu_item_parent != $parent_id ): ?> </li> <?php $submenu = false; endif; ?> <?php $count++; endforeach; ?>