其主要用途是通过该方法,
实现配景的天生菜单调用。
使用该功能之前,必须激活主题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' ) ) ?>
根据是否登录天生差异该菜单栏
<?php
if ( is_user_logged_in() ) {
wp_nav_menu( array( 'theme_location' => 'logged-in-menu' ) );
} else {
wp_nav_menu( array( 'theme_location' => 'logged-out-menu' ) );
}
?>
移除菜单栏
<?php
function my_wp_nav_menu_args( $args = '' )
{
$args['container'] = false;
return $args;
} // function
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
?>
大概
<?php wp_nav_menu( array( 'container' => '' ) ); ?>
天生的菜单css风格为
可以通过
复制代码
| 'before'[/code] => ,<BR> [/code]'after'[/code] => ,<BR> [/code]'link_before'[/code] => ,<BR> [/code]'link_after'[/code] => ,<BR>[/code] | 添加使用的标签,并对其进行css美化,可以让你得到心中想要的结果。 |