drus39136 2017-01-08 14:51
浏览 177
已采纳

在wordpress模板中添加自定义导航菜单

I'm trying to add a custom menu over my WordPress site inside a template page. I've successfully registered new menu with this code

      function register_my_menu() {

      register_nav_menu('new-menu',__( 'New Menu' ));
    }

     add_action( 'init', 'register_my_menu' );

Now I've added this menu inside page.php and successfully getting menu items over my wordpress pages

 < ? php wp_nav_menu( array( 'theme_location' => 'new-menu' ) ); ?>

The question is I'm seeing the menu items vertical like this http://prntscr.com/dt6300 . How can I style my custom menu? If someone could give a hint!

  • 写回答

1条回答 默认 最新

  • dongronge3732 2017-01-08 15:54
    关注

    it depends on what kind of menu you want to make. You can inspect the code on the browser to see the classes of the generated HTML and create the relative CSS for each element. you can pass the container argument to wp_nav_menu:

    https://developer.wordpress.org/reference/functions/wp_nav_menu/

    'container'

    (string) Whether to wrap the ul, and what to wrap it with. Default 'div'.

    and the following arguments to give id and class to the elements:

    'menu_class'

    (string) CSS class to use for the ul element which forms the menu. Default 'menu'.

    'menu_id' (string)

    The ID that is applied to the ul element which forms the menu. Default is the menu slug, incremented.

    'container_class' (string)

    Class that is applied to the container. Default 'menu-{menu slug}-container'.

    'container_id' (string)

    The ID that is applied to the container.

    You can also see here: https://codex.wordpress.org/Creating_Horizontal_Menus

    <?php wp_nav_menu( array( 'theme_location' => 'new-menu', 'menu_class' => 'mymenuclass', 'menu_id' => 'mymenuid', 'container_class' => 'mycontainerclass' ) ); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 Matlab图例修改
  • ¥15 rk3566 Android11 USB摄像头 微信
  • ¥15 torch框架下的强化学习DQN训练奖励值浮动过低,希望指导如何调整
  • ¥35 西门子博图v16安装密钥提示CryptAcquireContext MS_DEF_PROV Error of containger opening
  • ¥15 mes系统扫码追溯功能
  • ¥40 selenium访问信用中国
  • ¥20 在搭建fabric网络过程中遇到“无法使用新的生命周期”的报错
  • ¥15 Python中关于代码运行报错的问题
  • ¥500 python 的API,有酬谢
  • ¥15 软件冲突问题,软件残留问题
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部