WordPress.org

Ready to get started?Download WordPress

Forums

Custom Menus on Different Pages (4 posts)

  1. dcstover1
    Member
    Posted 2 years ago #

    Ive tried for hours. I cannot seem to get a seperate menu working for a new page I have created. I have found a good forum thread from about a year ago explaining how to do it, but still doesnt work...only creates a seperate menu above my own.

    I created a seperate menu within appearance, called it "properties" went into my page itself (where i want this menu to appear) and created a custom field called "MenuName" with the value of "properties". I then went into my header.php file and pasted the folowing code..<?php wp_nav_menu( array( 'container' => 'none', 'container_class' => 'menu-header', 'theme_location' => 'primary', 'menu' => get_post_meta( $post->ID, 'MenuName', true) ) ); ?>

    the result is that it yeilds my new menu above my default menu...so obvioulsly im thinking i need to replace the original wp_nav_menu code, but cannot find it anywhere within header or any other php file. Im using the theme "Striking" if this helps.

    Thanks in advance guys!

  2. toocoolone
    Member
    Posted 2 years ago #

    Your call to wp_nav_menu() contains two parameters that could cause this. By setting 'theme_location' and 'menu' you're calling the primary (default) menu in your theme and then the specialized theme for your page.

    I'd fetch the post_meta and put it in a variable then pick which menu to display like this:

    <?php
    $myThemeTest = get_post_meta( $post->ID, 'MenuName', true );
    if( $myThemeTest == '' ) {
    	wp_nav_menu(
    		array(
    			'container' => 'none',
    			'container_class' => 'menu-header',
    			'theme_location' => 'primary',
    		)
    	);
    } else {
    	wp_nav_menu(
    		array(
    			'container' => 'none',
    			'container_class' => 'menu-header',
    			'menu' => $myThemeTest,
    		)
    	);
    }
    ?>

    I don't have the source available to me from this theme so I don't know where the initial wp_nav_menu call is. But if you're still getting duplicates after this change, you're most likely going to have to find the original wp_nav_menu call and replace it with this. You might try a multi-file text search for wp_nav_menu through the theme's files.

  3. dcstover1
    Member
    Posted 2 years ago #

    Thanks a lot! But actually now that I see it, im going to need to change both header and footer for these pages. That being said wouldnt it be easier for me to go into my page.php file and change the header and footer file it is calling for these specific pages? Of course id have to make another header and footer file and call them something like header-alt.php ect. but that wouldnt be a problem.

    But since im new to php id have no idea how to make that code work.

  4. toocoolone
    Member
    Posted 2 years ago #

    The header.php and footer.php files that are in there with the page.php file are the ones you're going to want to change. You can put the code above where ever there's a menu call and it will choose between the regular menu or the specialized page menu for you. Just replace the existing wp_nav_menu(); call in your header or footer files with that code and it should handle the rest.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.