Warning: Illegal string offset 'top' in /www/wwwroot/hellyhua.com/wp-content/themes/Snape/single.php on line 45
wp_nav_menu()方法位于wp-includes/nav-menu-templates.php文件中。
其主要用途是通过该方法,
实现后台的生成菜单调用。
使用该功能之前,必须激活主题3.0+菜单功能。
方法如下:
在functions.php文件中加入
add_theme_support( 'nav-menus' );或者
- // 自定义菜单
- register_nav_menus(
- array(
- ‘header-menu’ => __( ’导航自定义菜单’ ),
- ‘footer-menu’ => __( ’页角自定义菜单’ )
- )
- );
简单调用如下:
<?php wp_nav_menu($args);?>
调用的menu默认排版为
<?php $defaults = array( 'theme_location' => , 'menu' => , 'container' => 'div', 'container_class' => 'menu-{menu slug}-container', 'container_id' => , 'menu_class' => 'menu', 'menu_id' => , 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => , 'after' => , 'link_before' => , 'link_after' => , 'depth' => 0, 'walker' => );?>
如果是多菜单的话,如下调用
<?php echo wp_nav_menu( array( ‘container_class’ => ‘menu-header’, ‘theme_location’ => ‘primary’ ) ) ?>
根据是否登录生成不同该菜单栏
<?phpif ( is_user_logged_in() ) { wp_nav_menu( array( 'theme_location' => 'logged-in-menu' ) );} else { wp_nav_menu( array( 'theme_location' => 'logged-out-menu' ) );}?>移除菜单栏<?phpfunction my_wp_nav_menu_args( $args = '' ){ $args['container'] = false; return $args;} // functionadd_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );?>或者<?php wp_nav_menu( array( 'container' => '' ) ); ?>生成的菜单css风格为可以通过
'before' => , 'after' => , 'link_before' => , 'link_after' => ,添加使用的标签,并对其进行css美化,可以让你获得心中想要的效果。
Warning: Illegal string offset 'footer' in /www/wwwroot/hellyhua.com/wp-content/themes/Snape/single.php on line 49