• Resolved cbc-adsmith

    (@cbc-adsmith)


    I’m trying to change the menu navigation for a specific page. I want one page to use “Menu 1” and another page to use “Menu 2”. Is this possible? I can’t find any solution.

    If it’s not possible, could I achieve this by setting up my WordPress to be a “Multisite” and then having different Menus for each “Multisite”?

    Thanks for any help on this matter!

Viewing 14 replies - 1 through 14 (of 14 total)
  • Yes – that’s possible if you register more than 1 menu. Eg:

    FUNCTIONS.PHP

    function register_my_menus() {
    	register_nav_menu( 'foo', __( Name1') );
    	register_nav_menu( 'bar', __( 'Name2' ) );
    }
    add_action( 'init', 'register_my_menus' );

    TEMPLATE FILE

    <?php
    $args = array();
    if (is_page('cat') ) $args['theme_location'] = 'foo';
    else $args['theme_location'] = 'bar';
    wp_nav_menu($args);?>

    Thread Starter cbc-adsmith

    (@cbc-adsmith)

    That gave me the option to set multiple menus!

    But how do I change which menu each specific page uses?

    The menu foo will be used on the Page with the slug of cat. Anything else will use menu bar. So you simply adjust the code to suit your needs.

    Thread Starter cbc-adsmith

    (@cbc-adsmith)

    It is still not working as far as the actual page template. It’s listing out all the pages and then showing the correct navigation menu but it’s in a “widget” style vertical lineup

    See what I mean: https://lcskleenaire.com/lcsi/

    Do I need to create multiple page templates or something?

    Thread Starter cbc-adsmith

    (@cbc-adsmith)

    Here is my code:

    Functions:

    function register_my_menus() {
    		register_nav_menu( 'lcs', __( 'LCS Menu') );
    		register_nav_menu( 'lcsi', __( 'LCSi Menu' ) );
    	}
    	add_action( 'init', 'register_my_menus' );

    Page Template:

    <?php
    $args = array();
    if (is_page('lcs') ) $args['theme_location'] = 'lcs';
    else $args['theme_location'] = 'lcsi';
    wp_nav_menu($args);?>

    The vertical display is a CSS/theme issue. Nothing to do with the code itself. Have you created your two custom menus?

    Thread Starter cbc-adsmith

    (@cbc-adsmith)

    Yes, both menus are created and assigned correctly.

    Why is it suddenly adding menu links that I haven’t created? I haven’t changed anything with the theme CSS and it was working before these changes.

    According to the source markup, every one of the nav links on the home page has been manually added to a custom menu.

    Thread Starter cbc-adsmith

    (@cbc-adsmith)

    I see that in the source too, but there is not a custom menu with the “Splash” page included, so I’m not sure where it’s pulling those links from. Is there any other cause for those links to show up? And why are the correct menu items not showing up as the theme’s navigation menu?

    I’m not sure what you mean by “splash page”?

    Thread Starter cbc-adsmith

    (@cbc-adsmith)

    On the page (https://lcskleenaire.com/lcsi/) you can see a link showing up that says “Splash” which was not added to any custom menu, yet it’s showing up now that I’ve made these changes.

    Thanks for your help. I will continue to work with it. I changed the slug to match but it’s still not working.

    Thread Starter cbc-adsmith

    (@cbc-adsmith)

    *Update*

    I added the code that esmi provided for the page template (page.php) to the header (header.php) instead, and it worked!

    Thanks for your help, esmi!

    Newbie to WP and the forums. Is it OK to tag onto an issue like this, or do I start one fresh? I might be able to use a similar solution and would like suggestions. I need 15 “section” sidebar menus across 150 pages to even get started with my migration to WP. Top main menu is static.

    Is mine a whole different hair ball situation requiring custom page templates that call custom sidebar templates that then include custom menus?

    Just looking to get headed in the right direction. Not looking for the complete code…

    Apologies if this is improper etiquette. Let me know.

    Thread Starter cbc-adsmith

    (@cbc-adsmith)

    *Update*

    I was trying to change more than just one specific page using an “if” and “else” conditional statement. I wasn’t sure how to force a second if statement, and nothing I tried was working (such as adding a comma between slugs, or just adding another if statement line). After reading this article about wordpress conditional statements, I realized I could create “elseif” statements and then end with a final “else” statement. Perhaps this was a dumb oversight, but at least I figured it out! Wanted to update in case anyone else read this.

    This method is especially useful for breaking up a WordPress into two different sites, sort of. Client wanted a splash page that directed to two different sides of the same parent company website, each with different navigation menus.

    Thanks again esmi for the help.

    @blachance – sounds like a different issue. You should be able to customize your sidebars using widgets, I believe. You might get more responses if you start a new topic or further research the problem and find a more relevant question topic.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Is it possible to have different menus for different pages?’ is closed to new replies.