WORDPRESS博客有些主题不支持自定义菜单,只能够选择页面和所有的分页目录作为菜单,所以为了解决这一问题,找了一些资料
在这个之前首先对wordpress的wp_nav_menu() 函数应该了解:
使用方法如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| wp_nav_menu( array( 'theme_location' => '' 'menu' => 'header-menu', 'container' => 'nav', 'container_class' => 'primary', 'container_id' => '', 'menu_class' => 'sf-menu', 'menu_id' => 'topnav', 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => 'depth' => 0, 'walker' => ''
|
为了能够使后台支持自定义菜单,我们需要在主题下functions.php下 加入register_nav_menus():
1 2 3 4 5 6 7 8 9
| if(function_exists('register_nav_menus')){ register_nav_menus( array( 'header-menu' => __( '导航自定义菜单' ), ) ); }
|
在添加之后,你就会发现主题位置已经支持一个菜单了
然后找到header.php文件, 类似这样添加:
1 2 3 4 5 6
| <?php wp_nav_menu(array( 'theme_location'=>'header-menu', )); ?>
|
好了, 大家可以自己制作属于自己的自定义菜单了~