Created
July 21, 2012 20:32
-
-
Save gyrus/3157067 to your computer and use it in GitHub Desktop.
Get menu items of WordPress nav menu attached to specified menu location
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
| <?php | |
| /** | |
| * Get menu items of nav menu attached to specified menu location | |
| * | |
| * @uses get_nav_menu_locations() | |
| */ | |
| function pilau_get_menu_location_items( $location_slug, $max = 0 ) { | |
| static $menu_locations = null; | |
| if ( $menu_locations === null ) | |
| $menu_locations = get_nav_menu_locations(); | |
| $menu = $menu_locations[ $location_slug ]; | |
| $menu = wp_get_nav_menu_items( $menu ); | |
| if ( $max && count( $menu ) > $max ) | |
| $menu = array_slice( $menu, 0, $max ); | |
| $items = array(); | |
| foreach ( $menu as $menu_item ) | |
| $items[] = get_post( $menu_item->object_id ); | |
| return $items; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment