Created
July 4, 2013 02:55
-
-
Save collinprice/5924576 to your computer and use it in GitHub Desktop.
Wordpress Divided 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 characters
function slice_menu($menu_name) { | |
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); | |
$menu_list = '<dl class="sub-nav">'; | |
$menu_counter = count($menu_items); | |
foreach ( (array) $menu_items as $key => $menu_item ) { | |
$title = $menu_item->title; | |
$url = $menu_item->url; | |
$menu_list .= '<dd><a href="' . $url . '">' . $title . '</a></dd>'; | |
$menu_counter-- != 1 ? | |
$menu_list .= '<dd>|</dd>' | |
: ''; | |
} | |
$menu_list .= '</dl>'; | |
} else { | |
$menu_list = '<dl><dd>Menu "' . $menu_name . '" not defined.</dd></dl>'; | |
} | |
echo $menu_list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment