WordPress.org

Ready to get started?Download WordPress

Forums

Selecting a defferent menu depending on page (2 posts)

  1. rtivel
    Member
    Posted 3 years ago #

    Hi,
    I have created different pages (home, blog, directory, sitemap, about, contact) that I want to use in the navbar. Individual menu items will appear in the nav bar depending on the page being displayed. If I create the page menus I want to display by using the menu option from the dashboard and give each menu a different name (for example, about_menu), is there an easy way to select the appropriate menu for the page a visitor is on? For example, if a visitor is on the about page, I would like to use the "about_menu". I know I can do this by creating a manual list and using "if" and "else" in the header.php file, but this is a manual operation and doesn't take advantage of the menu facility:

    <div id="access" role="navigation">
    			  				<div class="skip-link screen-reader-text"><a href="#content" title="Skip to content">Skip to content</a></div>
    
    				<div class="menu-header"><ul id="menu-post_menu" class="menu">
    
    <?php if ( is_home() || is_page('directory') ) { ?>
    <?php } else { ?>
    <?php if (is_single()) { ?>
    <li id="menu-item-39" class="menu-item menu-item-type-post_type menu-item-39"><a href="http://localhost/">Home</a></li>
    <?php } ?>
    <li id="menu-item-38" class="menu-item menu-item-type-post_type current_page_parent menu-item-38"><a href="http://localhost/blog">Blog</a></li>
    
    <li id="menu-item-37" class="menu-item menu-item-type-post_type menu-item-37"><a href="http://localhost/directory">Directory</a></li>
    <?php if ( is_page('sitemap') || is_page('about') ) { ?>
    <?php } else { ?>
    <li id="menu-item-36" class="menu-item menu-item-type-post_type menu-item-36"><a href="http://localhost/sitemap">Sitemap</a></li>
    <?php } ?>
    <?php if ( is_front_page() || is_page('sitemap') ) { ?>
    <li id="menu-item-45" class="menu-item menu-item-type-post_type menu-item-45"><a href="http://localhost/about">About</a></li>
    <?php } else { ?>
    <?php } ?>
    
    <?php } ?>
    </ul></div>			</div><!-- #access -->

    Any help on this would be appreciated.

  2. rtivel
    Member
    Posted 3 years ago #

    I found the relevant reference for this (Function Reference/wp nav menu) at http://codex.wordpress.org/Function_Reference/wp_nav_menu . This is what I need to utilize custom menus for specific pages.

Topic Closed

This topic has been closed to new replies.

About this Topic