Different menu navigation per category

Hello all you helpful people 🙂

I am using a self modified version of the 2012 theme and I would like to be able to display a different main navigation menu based on the category I am viewing.

Read More

Firstly is there a plugin for such a thing as a GUI would be easier for me to get to grips with

If not I’m guessing it will be PHP in the header.php file? I already have if statements for custom headers per category so I can add the additional code for switching menus in here.

Any help is great 🙂

My existing menu code is:

<nav id="site-navigation" class="main-navigation" role="navigation">
            <h3 class="menu-toggle"><?php _e( 'Menu', 'twentytwelve' ); ?></h3>
            <a class="assistive-text" href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentytwelve' ); ?>"><?php _e( 'Skip to content', 'twentytwelve' ); ?></a>
            <?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?>
        </nav><!-- #site-navigation -->

Main menu is called ‘Talkative’
Custom menu is called ‘Pirtek’

I cannot see in the existing code what would be changed unless I have to add additional function calls to wp_nav_menu for example

<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' 'menu' => 'Talkative') ); ?>

Related posts

1 comment

  1. Try the following

    <nav id="site-navigation" class="main-navigation" role="navigation">
        <h3 class="menu-toggle"><?php _e( 'Menu', 'twentytwelve' ); ?></h3>
        <a class="assistive-text" href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentytwelve' ); ?>"><?php _e( 'Skip to content', 'twentytwelve' ); ?></a>
        <?php
        //Replace it with the id/slug/name(anything you want)
        if( is_category( 'Talkative' ) ) {
            wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu', 'menu' => 'Talkative') );
        } elseif( is_category( 'Pirtek' ) ) {
            wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu', 'menu' => 'Pirtek') );
        } else {
            wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) );
        }
        ?>
    </nav><!-- #site-navigation -->
    

    Haven’t tried it, but this should work.

    For details check is_category() and wp_nav_menu()

Comments are closed.