WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Is it possible to have different menus for different pages? (15 posts)

  1. cbc-adsmith
    Member
    Posted 1 year ago #

    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!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    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);?>
  3. cbc-adsmith
    Member
    Posted 1 year ago #

    That gave me the option to set multiple menus!

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

  4. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    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.

  5. cbc-adsmith
    Member
    Posted 1 year ago #

    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: http://lcskleenaire.com/lcsi/

    Do I need to create multiple page templates or something?

  6. cbc-adsmith
    Member
    Posted 1 year ago #

    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);?>
  7. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

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

  8. cbc-adsmith
    Member
    Posted 1 year ago #

    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.

  9. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

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

  10. cbc-adsmith
    Member
    Posted 1 year ago #

    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?

  11. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    I'm not sure what you mean by "splash page"?

  12. cbc-adsmith
    Member
    Posted 1 year ago #

    On the page (http://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.

  13. cbc-adsmith
    Member
    Posted 1 year ago #

    *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!

  14. blachance
    Member
    Posted 1 year ago #

    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.

  15. cbc-adsmith
    Member
    Posted 1 year ago #

    *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.

Topic Closed

This topic has been closed to new replies.

About this Topic