How to fetch the menu at custom template dynamically in wordpress?

时间:2018-05-14 17:34:09

标签: wordpress

i want to fetch the menu with items dynamically.. This is my code what i have tried :

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

1 个答案:

答案 0 :(得分:0)

首先,将此代码添加到 functions.php 文件中。

register_nav_menus( array(
    'header-top' => __( 'Header Top', 'twentyseventeen' )
) );

然后在 index.php 上添加对我有用的内容。

?php if ( has_nav_menu( 'header-top' ) ) : ?>
                                <?php wp_nav_menu( array(
                                    'theme_location' => 'header-top',
                                    'menu_id'        => 'header-top',
                                ) ); ?>
                            <?php endif; ?>