drus39136 2017-01-08 22: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 23: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 clousx6整点报时指令怎么写
  • ¥30 远程帮我安装软件及库文件
  • ¥15 关于#自动化#的问题:如何通过电脑控制多相机同步拍照或摄影(相机或者摄影模组数量大于60),并将所有采集的照片或视频以一定编码规则存放至规定电脑文件夹内
  • ¥20 深信服vpn-2050这台设备如何配置才能成功联网?
  • ¥15 Arduino的wifi连接,如何关闭低功耗模式?
  • ¥15 Android studio 无法定位adb是什么问题?
  • ¥15 C#连接不上服务器,
  • ¥15 angular项目错误
  • ¥20 需要帮我远程操控一下,运行一下我的那个代码,我觉得我无能为力了
  • ¥20 有偿:在ubuntu上安装arduino以及其常用库文件。