开发者

Wordpress child theme, adding secondary menu

    <?php
    if ( function_exists('has_nav_menu') && has_nav_menu('primary-menu') ) {
        wp_nav_menu( array( 'sort_column' => 'menu_o开发者_运维百科rder', 'container' => 'ul', 'menu_id' => 'main-nav', 'menu_class' => 'nav fl', 'theme_location' => 'primary-menu' ) );
    } else {
    ?>

I'm trying to add a secondary menu from Wordpress menu management in my functions.php of my child theme for Woothemes Canvas. I figure there's a way to add it to the array above but I can't get it to work. Thoughts?


Jason, you first need to register your 'new' (secondary) menu with register_nav_menu() like:

add_action( 'init', 'register_my_menu' );

function register_my_menu() {
    register_nav_menu( 'secondary-menu', __( 'Secondary Menu' ) );
}

You do this in your theme's functions.php file.

Then you're able to call that menu in your template files. To use your code above, you'll probably want something like:

if ( function_exists('has_nav_menu') && has_nav_menu('secondary-menu') ) {
        wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'secondary-nav', 'menu_class' => 'nav fl', 'theme_location' => 'secondary-menu' ) );
    }

or maybe

if ( function_exists('has_nav_menu') && has_nav_menu('primary-menu') && has_nav_menu('secondary-menu') ) {
        wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'main-nav', 'menu_class' => 'nav fl', 'theme_location' => 'primary-menu' ) );

        wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'secondary-nav', 'menu_class' => 'nav fl', 'theme_location' => 'secondary-menu' ) );
    }

The second one will output both menus if they both exist, the first one will probably be used in addition to the one you posted in your initial question.


But in my case, I did not use the init action, just put the menu register function in my child theme's function.php file

register_nav_menu( 'footer', 'Footer Menu' );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜