在WordPress主题中自定义菜单

1. 首先在主题的functions.php中注册菜单:

register_nav_menus(array(
'primary_nav' => 'Primary Navigation',
'secondary_nav' => 'Primary Navigation'
));

2. 在后台的 Appearance -> Menus 中设置菜单项。

3. 在主题中显示菜单:

wp_nav_menu( array('menu_class' => 'primary_nav', 'theme_location' =>'primary_nav') );

wp_nav_menu(); 函数支持丰富的参数,详情参考官方文档:
http://codex.wordpress.org/Function_Reference/wp_nav_menu

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

You are commenting using your WordPress.com account. Log Out /  更改 )

Google photo

You are commenting using your Google account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

Connecting to %s