add menu slots/theme_menus, props ryan, see #13378

git-svn-id: http://svn.automattic.com/wordpress/trunk@14611 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
wpmuguru 2010-05-13 22:14:54 +00:00
parent b38af2d56d
commit 21bef33fc6
5 changed files with 46 additions and 4 deletions

View File

@ -482,7 +482,18 @@ require_once( 'admin-header.php' );
<input name="menu-name" id="menu-name" type="text" class="menu-name regular-text menu-item-textbox input-with-default-title" title="Enter menu name here." value="<?php echo esc_attr( $nav_menu_selected_title ); ?>" />
<br class="clear" />
</label>
<?php if ( ! empty( $nav_menu_selected_id ) && $slots = get_registered_nav_menus() ) : ?>
<label class="menu-name-label howto open-label" for="menu-slot">
<span><?php _e('Theme Menu'); ?></span>
<select id="menu-slot" name="menu-slot">
<?php foreach ( $slots as $slot_key => $slot_text ) {
echo '<option value="' . esc_attr($slot_key) . '">' . esc_html($slot_text) . '</option>';
}
?>
</select>
<br class="clear" />
</label>
<?php endif; ?>
<div class="publishing-action">
<input class="button-primary" name="save_menu" type="submit" value="<?php empty($nav_menu_selected_id) ? esc_attr_e('Create Menu') : esc_attr_e('Save Menu'); ?>" />
</div><!--END .publishing-action-->

View File

@ -80,7 +80,7 @@ function twentyten_setup() {
add_theme_support( 'post-thumbnails' );
// This theme uses wp_nav_menu()
add_theme_support( 'nav-menus' );
register_nav_menus( array('main' => __('Main Menu')) );
// Add default posts and comments RSS feed links to head
add_theme_support( 'automatic-feed-links' );

View File

@ -69,7 +69,7 @@
<div id="access" role="navigation">
<div class="skip-link screen-reader-text"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentyten' ); ?>"><?php _e( 'Skip to content', 'twentyten' ); ?></a></div>
<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header' ) ); ?>
<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header', 'theme_menu' => 'main' ) ); ?>
</div><!-- #access -->
</div><!-- #masthead -->
</div><!-- #header -->

View File

@ -193,7 +193,7 @@ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
function wp_nav_menu( $args = array() ) {
$defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'menu_class' => 'menu', 'echo' => true,
'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '',
'depth' => 0, 'walker' => '', 'context' => 'frontend' );
'depth' => 0, 'walker' => '', 'context' => 'frontend', 'theme_menu' => '' );
$args = wp_parse_args( $args, $defaults );
$args = apply_filters( 'wp_nav_menu_args', $args );
@ -202,6 +202,12 @@ function wp_nav_menu( $args = array() ) {
// Get the nav menu
$menu = wp_get_nav_menu_object( $args->menu );
if ( ! $menu && $slot ) {
$slots = get_nav_menu_slots();
if ( isset($slots) && isset($slots['theme_menu']) )
$menu = wp_get_nav_menu_object( $slots['theme_menu'] );
}
// If we couldn't find a menu based off the menu argument
// get the first menu that has items.
if ( ! $menu ) {

View File

@ -61,6 +61,31 @@ function is_nav_menu( $menu ) {
return false;
}
/**
* Register nav menus for a theme.
*
* @since 3.0.0
*
* @param array Associative array of menu slot identifiers and descriptions.
*/
function register_nav_menus( $menus = array() ) {
global $_wp_registered_nav_menus;
add_theme_support( 'nav-menus' );
$_wp_registered_nav_menus = $menus;
}
function get_registered_nav_menus() {
global $_wp_registered_nav_menus;
return $_wp_registered_nav_menus;
}
function get_nav_menu_slots() {
return get_theme_mod('nav_menu_slots');
}
/**
* Determine whether the given ID is a nav menu item.
*