Skip to content

Instantly share code, notes, and snippets.

@hitautodestruct
Created May 13, 2013 11:36
Show Gist options
  • Save hitautodestruct/5567717 to your computer and use it in GitHub Desktop.
Save hitautodestruct/5567717 to your computer and use it in GitHub Desktop.
A short wordpress menu generator with only top level links. No hierarchy.
<?php
$menu_name = 'sidebar_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' ) );
?>
<ul class="side-menu">
<?php
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 );
?>
<li class="item">
<a href="<?php echo $link; ?>" class="title">
<?php echo $page->post_title; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment