将自定义菜单添加到我的WordPress主题的顶部导航

时间:2017-10-08 23:25:51

标签: php wordpress

我想在主题的顶部导航中添加自定义菜单。我有一个插件,当激活时,会自动将活动主题切换到我目前正在制作的主题。现在,只显示默认菜单。我不确定这是注册启动器内容的问题还是显示正确菜单的问题。这是我的代码:

在ThemeName / functions.php中:

function theme_support(){

...

register_nav_menus( array(
        'top'    => __( 'Top Menu', 'PinkVulture' )
    ) );

add_theme_support('starter-content', array(
    ...
    'nav_menus' => array(
            // Assign a menu to the "top" location.
            'top' => array(
                'name' => __( 'Top Menu', 'PinkVulture' ),
                'items' => array(
                    'link_home' => array(
                        'title' => 'Home',
                        'url' => site_url()
                    ), // Note that the core "home" page is actually a link in case a static front page is not used.
                    'page_menu' => array(
                        'title' => 'Menu',
                        'url' => site_url('/menu')
                    ),
                    'page_specials' => array(
                        'title' => 'Specials',
                        'url' => site_url('/specials')
                    ),
                    'page_groups' => array(
                        'title' => 'Groups',
                        'url' => site_url('/groups')
                    ),
                    'page_events' => array(
                        'title' => 'Events',
                        'url' => site_url('/events')
                    ),
                    'page_about' => array(
                        'title' => 'About',
                        'url' => site_url('/about')
                    ),
                    'page_contact' => array(
                        'title' => 'Contact',
                        'url' => site_url('/contact')
                    )
                )
            ),
    ...
    ));

}

add_action( 'after_setup_theme', 'theme_support' );

在ThemeName / header.php中:

...
                <nav>
                    <ul>
                        <?php wp_nav_menu( array(
                            'theme_location' => 'top'
                        ) ); ?>
                    </ul>
                </nav><!-- .navigation-top -->
...

0 个答案:

没有答案