Skip to content

Instantly share code, notes, and snippets.

@natejacobson
Last active April 29, 2016 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natejacobson/396bbd0edcc64dbcba4782debed5c273 to your computer and use it in GitHub Desktop.
Save natejacobson/396bbd0edcc64dbcba4782debed5c273 to your computer and use it in GitHub Desktop.
Datalist <dl> nav menu in WordPress
<nav>
<dl>
<?php
$menu_name = '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;
foreach( $menuitems as $item ):
$link = $item->url;
$title = $item->title;
if ( !$item->menu_item_parent ) { // not parent so menu_item_parent equals 0 (false)
if ($count >= 0) {
echo '</dl>';
}
echo '<dl>';
echo '<dt>'.$title.'</dt>'; // Just wanted a link group header, so this isn't linked.
} else {
echo '<dd>';
echo '<a href='.$link.' class="title">'.$title.'</a>';
echo '</dd>';
}
$count++;
endforeach;
?>
</dl>
</nav>
@natejacobson
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment