简体   繁体   English

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

[英]Add custom navigation menu in wordpress template

I'm trying to add a custom menu over my WordPress site inside a template page. 我正在尝试在模板页面内的WordPress网站上添加自定义菜单。 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 现在,我已将此菜单添加到page.php中,并成功在我的wordpress页面上获取了菜单项

 < ? 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 . 问题是我看到像http://prntscr.com/dt6300这样的垂直菜单项。 How can I style my custom menu? 如何为自定义菜单设置样式? If someone could give a hint! 如果有人可以提示!

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. 您可以在浏览器上检查代码以查看生成的HTML的类,并为每个元素创建相对的CSS。 you can pass the container argument to wp_nav_menu : 您可以将container参数传递给wp_nav_menu

https://developer.wordpress.org/reference/functions/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. (字符串)是否包装ul,以及包装什么。 Default 'div'. 默认为“ div”。

and the following arguments to give id and class to the elements: 以及用于为元素赋予id和class的以下参数:

' menu_class ' ' menu_class '

(string) CSS class to use for the ul element which forms the menu. (字符串)用于构成菜单的ul元素的CSS类。 Default 'menu'. 默认为“菜单”。

' menu_id ' (string) ' menu_id '(字符串)

The ID that is applied to the ul element which forms the menu. 应用于构成菜单的ul元素的ID。 Default is the menu slug, incremented. 默认为菜单项,递增。

' container_class ' (string) ' container_class '(字符串)

Class that is applied to the container. 应用于容器的类。 Default 'menu-{menu slug}-container'. 默认为“菜单-{菜单子弹}-容器”。

' container_id ' (string) ' container_id '(字符串)

The ID that is applied to the container. 应用于容器的ID。

You can also see here: https://codex.wordpress.org/Creating_Horizontal_Menus 您也可以在这里看到: https : //codex.wordpress.org/Creating_Horizo​​ntal_Menus

<?php wp_nav_menu( array( 'theme_location' => 'new-menu', 'menu_class' => 'mymenuclass', 'menu_id' => 'mymenuid', 'container_class' => 'mycontainerclass' ) ); ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM