Different Menus on Different Pages

Trying to have different navigation menus on different pages. My theme doesn’t let me edit the functions page. I created a new header template and page template. I want to change the menu used in the new header template, but I don’t understand what the code below means so I’m not exactly sure what to change.

I’m trying to learn so could someone help translate what this code means?

<ul id="menu-hosting-menu" class="curved">
                    <?php if ( is_page() ) $highlight = 'page_item'; else $highlight = 'page_item 

current_page_item'; ?>
                    <li class="<?php echo $highlight; ?> menu-item menu-item-type-custom menu-item-object-custom"><a href="<?php echo home_url( '/' ); ?>">Home</a></li>
                    <?php wp_list_pages( 'sort_column=menu_order&depth=3&title_li=&exclude=' ); ?>
                </ul><!-- /#nav -->
                <?php }  ?>

                 <select> 
                    <option value="" selected="selected">Select</option> 
                    <?php
                    $menu_name = 'primary-menu'; //same as theme_location
                    if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ 

 $menu_name ] ) ) {
                        $menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
                        $menu_items = wp_get_nav_menu_items($menu->term_id);
                        var_dump($menu_items);
                        foreach ( (array) $menu_items as $key => $menu_item ) {
                            $title = $menu_item->title;
                            $url = $menu_item->url;
                            if($menu_item->menu_item_parent){
                                $title = '-- '.$title;
                            }
                            $menu_list .= '<option value="' . $url . '">' . $title . 

 '</option>'; 
   }} else {
                        $menu_list .= '<option  value="">Menu "' . $menu_name . '" not 

defined.</option>';
                    }
                    echo $menu_list;
                    ?>
                  </select> 



        </nav>

Related posts

Leave a Reply

2 comments

  1. Are you trying to load the menu on an entirely new template, or just a particular page?

    I imagine one (simple) approach to this would be to create both a new page template, and a new header. You would simply then tell the new page template (selectable in your Admin panel in the CMS) to call the new (custom) header as well.

    A great explanation on how this can be done is found here:

    http://reflectingthedesigner.com/wordpress/2011/10/24/creating-a-new-wordpress-page-template/

    Hope this helps.

  2. Figured it out. I just deleted all of that code above and replaced it with

    <?php wp_nav_menu( array('menu' => 'Hosting' )); ?>
    

    Worked like a charm.