• I am developing a website for a client using WP and would like to display different menus on different pages. So for instance if a user selected the Profile page the sidebar would display the profile menu, if they selected the services page it would display the services menu and so on…

    I can create a custom menu and have also looked at custom page templates but I can’t work out how to add a specific custom menu to individual pages, or groups of pages.

    Firstly I was wondering if this was indead possible and if it is, some idea of how to do it would be really appreciated.

Viewing 7 replies - 16 through 22 (of 22 total)
  • teknohippy

    (@teknohippy)

    Err. I’m trying to remember what site I had to do this for!

    …Time passes…

    Okay found it, we’ll use it as an example.

    If you look at the homepage (https://gigajam.com/) you’ll see the site needed four main sections, one for each of guitar, bass, keyboard and drums. Now when you get into those sections I wanted a different main menu for each of the instruments. This is the tabbed menu right at the top. If you go into any of the instrument “schools” you’ll see it change.

    Now the code we’ve been discussing that outputs the menu is a function called wp_nav_menu. You’re theme will probably already have a call to this function in your header file.

    You can learn more about wp_nav_menu on its codex page.

    What is happening with the code as discussed above is that I am adding the following parameters to the wp_nav_menu call that was already in my header.

    `’menu’ => get_post_meta( $post->ID, ‘MenuName’, true)

    If you compare that to the codex page you can see that I’m passing something into the menu argument. What’s being passed in is the result of the call to get_post_meta(), which in pulling the value of MenuName out of the custom field for any given post/page.

    Chi Is Current

    (@jacobbarnett)

    teknohippy ~ Many Thanks, again, for your assistance here! I apologize for not quite getting this; there must be some particle I’m missing here.

    What is the complete name of the WP file in which the code (below) needs to be placed?

    —————–
    <?php wp_nav_menu( array( ‘container’ => ‘none’, ‘container_class’ => ‘menu-header’, ‘theme_location’ => ‘primary’, ‘menu’ => get_post_meta( $post->ID, ‘MenuName’, true) ) ); ?>
    —————–

    And where in that file does it need to be placed?

    teknohippy

    (@teknohippy)

    It can depend on the theme, but it would invariably be found in header.php.

    What theme are you using?

    Chi Is Current

    (@jacobbarnett)

    I’m using Twenty ten.

    I placed the code string:
    <?php wp_nav_menu( array( ‘container’ => ‘none’, ‘container_class’ => ‘menu-header’, ‘theme_location’ => ‘primary’, ‘menu’ => get_post_meta( $post->ID, ‘MenuName’, true) ) ); ?>

    In the header.php file, (trying both body, head and above the head). It only printed the page names at the top of the page.

    I have created a custom menu w/ menuname: CoachingMenu

    I have created a custom field on the page:
    Name: ‘MenuName’
    Value: ‘CoachingMenu’

    No joy.

    I’ll leave this up for a while for you to take a look at:
    https://counseling-coaching.com

    ???? — Jacob

    P.S. ~ What IS happening is the default menu names are appearing at the TOP of all pages EXCEPT the ‘Coaching’ page – on this page, the custom menu items are listed. The ‘Coaching’ page is where I am attempting to get the custom menu to appear.

    “Perseverance Furthers” – closer!

    Chi Is Current

    (@jacobbarnett)

    Chi Is Current

    (@jacobbarnett)

    OK! Got it! I appreciate your patience and perseverance here!!! Thank you!!!!

    Solution:
    Theme: Twenty Ten
    File: header.php
    Original Code Line: <?php wp_nav_menu( array( ‘container_class’ => ‘menu-header’, ‘theme_location’ => ‘primary’ ) ); ?>
    Revised Code Line: <?php wp_nav_menu( array( ‘container_class’ => ‘menu-header’, ‘theme_location’ => ‘primary’, ‘menu’ => get_post_meta( $post->ID, ‘MenuName’, true) ) );?>
    Also: “Then create a new custom field called MenuName and give it a value matching the name of the menu you want that page to use.”

    Nothing like reaching a solution! Thank you all for assisting this and my learning process here!

    With Best Regards, Jacob

    teknohippy

    (@teknohippy)

    Glad you’ve got it working, even happier you came to it yourself. You learn more that way.

    Cheers
    I

Viewing 7 replies - 16 through 22 (of 22 total)
  • The topic ‘Custom Menus on Different Pages’ is closed to new replies.