• Resolved maslerdanch

    (@maslerdanch)


    I have searched throughout the wordpress support to find some good information on customising the top level menu throughout a site.

    I have four sections in my site that require a different top level menu.

    The top level menu is called in the header in the usual way

    <?php wp_nav_menu(array('theme_location' => 'header-menu', 'container' => false, 'menu_class' => 'sf-menu', 'link_before' => '<span class="menu-btn">', 'link_after' => '</span>')); ?>

    Is there a way of 1. Applying different menus to different pages or 2.selecting a specific menu dependant on page slug or category it is in.

    Any help gratefully accepted!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hello there,

    You should definitely check out this thread.
    Basically, the quickest and simplest way of accomplishing what you are looking for is by registering multiple navigation menus, and calling them through a conditional php statement (if A then X) from your header.php file.
    Instead of testing whether the user is logged in (like in the above example thread), you can use the is_page and is_category functions.

    I hope this helps!

    Thread Starter maslerdanch

    (@maslerdanch)

    Thanks Marventus! I’ll have a read through and see what i can accomplish with that over the weekend!

    Hi,

    Where you able to figure this out? If so, could you please mark your topic as resolved?

    Thanks!

    Thread Starter maslerdanch

    (@maslerdanch)

    I have been registering the menus and it seems to work! Thanks

    I have employed another method to achieve this using WP Multisite. Create a network of sites, one sub-site for each ‘section’.

    As a bonus, you can theme each sub-site to help your visitors identify which section they’re in.

    Thread Starter maslerdanch

    (@maslerdanch)

    Thanks Superpotion – I had considered that but thought it was too much work in comparison.

    Can you search sitewide, i.e. through all the subsites?
    for instance if you are in site 1 can you do a search and it returns answers for site 2 & 3 as well as site 1?

    Good question. The default search will be restricted to the current sub-site, but I see there are a bunch of plugins that will do the job. Try Google “WordPress multi-site search” – I guess.

    Let us know if you find one that will hook on to the default search so that you don’t have to add widgets or modify code.

    Just to build on Marventus’s suggestions, as a neat alternative to a multi-site solution:

    (I’m using a TwentyEleven child theme in the example)

    add to functions.php:

    register_nav_menus( array(
    'section1'       => __( 'Section 1 Menu', 'mytheme'),
    'section2'       => __( 'Section 2 Menu', 'mytheme'),
    'section3'       => __( 'Section 3 Menu', 'mytheme')
    ) );

    add into header.php between the <nav> tags:

    <nav id="access" role="navigation">
       :
       :
    
    <?php /* Choose section menu depending on value of Custom Fields key: "section" */
    $sectmenu = "primary"; //set a defult in case we find nothing
    $sectmenu=get_post_meta($post->ID, 'section', true);
    switch ($sectmenu):
        case "1":
            wp_nav_menu( array( 'theme_location' => 'section1' ) );
            break;
        case "2":
            wp_nav_menu( array( 'theme_location' => 'section2' ) );
            break;
        case "3":
            wp_nav_menu( array( 'theme_location' => 'section3' ) );
            break;
        default:
            wp_nav_menu( array( 'theme_location' => 'primary' ) );
    endswitch ;   // 'primary' exists in TwentyEleven parent
    	 ?>
    
    </nav><!-- #access -->

    Now

    1. add Custom Field ‘section’ to each page/post and give it a value of 1, 2 or 3
    2. add custom menus in the dashboard
    3. add pages to your menus

    Voila!

    Denis

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Different 'Top Menus' on different pages/posts’ is closed to new replies.