WordPress.org

Ready to get started?Download WordPress

Forums

Assigned Nav Menus on a Per Page Basis using Custom Field (1 post)

  1. killerdesigner
    Member
    Posted 1 year ago #

    Happy New Year Everyone!

    Following several recommendations, I did get a custom menu to display on the page (see below), it was not in the right location, nor did it replace the "default" menu.

    I registered the desired menus by adding the code below to the theme's functions.php. The newly registered menus now display as shown here http://screencast.com/t/hnk73gV18:

    add_theme_support( ‘nav-menus’ );
    register_nav_menus( array(
    ‘mainnav’ => __( ‘Main Navigation’, ‘NorthVantage’ ),
    ‘corpnav’ => __( ‘Corporate Navigation’, ‘NorthVantage’ ),
    ‘cbonav’ => __( ‘CBO Navigation’, ‘NorthVantage’ ),
    ‘persnav’ => __( ‘Personal Navigation’, ‘NorthVantage’ ),
    ‘youthnav’ => __( ‘Youth Navigation’, ‘NorthVantage’ ),
    
    ) );

    I then added the code below to my header.php and the desired menu appeared, but not in place of the standard/default menu, and not in the same physical space, as shown here: http://screencast.com/t/mP2Ncy4Qz5n

    I found the wp_nav_menu in a file other than header.php. I believe the primary related snippet is shown below:

    if(get_option('wpcustomm_enable')!="disable") : // WP3.0 Custom Menu Support
    
                        $walker = new dyn_walker;
                        wp_nav_menu(array(
                        'echo' => true,
                        'container' => 'ul',
                        'menu_class'      => 'menu hide-on-phones',
                        'menu_id' => 'dyndropmenu',
                        'theme_location' => 'mainnav',
                        'walker' => $walker
                        ));  
    
                        if (!class_exists('UberMenu') && get_option('enable_responsive')!='disable') : // check if responsive is disabled
    
                        wp_nav_menu(array(
                        'theme_location' => 'mainnav',
                        'container' => 'div',
                        'container_class' => 'hide-on-desktops',
                        'container_id'    => 'nv_selectmenu',
                        'walker'         => new Walker_Nav_Menu_Dropdown(),
                        'items_wrap'     => '<select><option value="">'.__( 'Select a Page', 'NorthVantage' ).'</option>%3$s</select>'
                        ));
    
                        endif;

    I really don't know what to replace above with the code below to replace the default menu with the target menu specified in the custom field menuname of the page/post using the recommended code snippet below, and believe me, I've tried LOTS of variables, replacing this and that, adding this, taking that out, et cetera.

    $menu_slug = get_post_meta($post->ID,'menu',true);
    
    if(is_nav_menu($menu_slug)) {
        wp_nav_menu(array(
            'menu' => $menu_slug
        ));
    } // optionally, add an else to output something when no menu exists with the given meta value.

    OR this recommended snippet:

    wp_nav_menu( array( 'container' => 'none', 'container_class' => 'menu-header', 'theme_location' => 'primary', 'menu' => get_post_meta( $post->ID, 'MenuName', true) ) );

    Might a knowledgeable WPPHP person be able to assist with the correct code sequence to generate the desired output?

    I would be most appreciative.

Topic Closed

This topic has been closed to new replies.

About this Topic