视频:向WordPress二十一主题添加第二个菜单

The Twenty Ten theme only comes with one default menu, which is included in the header. However the theme also supports multiple menus, thanks to the use of  register_nav_menus(). Here’s a quick tip on how to take advantage of this function and add a second menu to the Twenty Ten theme.

二十个主题仅带有一个默认菜单,该菜单包含在标题中。 但是,由于使用了register_nav_menus() ,因此该主题还支持多个菜单。 这是有关如何利用此功能并将第二个菜单添加到第二十个主题的快速提示。

观看截屏 (Watch the Screencast)

Functions.php (Functions.php)

Open the functions.php file and look for:

打开functions.php文件,然后查找:

// This theme uses wp_nav_menu() in one location.

The next line is where we see the register_nav_menus() being used. As you can see this function accepts an array.

下一行是我们看到正在使用register_nav_menus()的地方。 如您所见,此函数接受数组。

register_nav_menus( array(
'primary' => __( 'Primary Navigation', 'twentyten' ),
) );

primary: this is a key, or name of the menu, this name should be unique within the array

primary:这是键或菜单的名称,此名称在数组中应唯一

__( ‘Primary Navigation’): this is the vaule of the key, or description of the menu

__('Primary Navigation'):这是按键的形式,或菜单的描述

To add the second menu simply add another key (menu name) and assign a value (enter description) into the array. Here’s an example of what it can look like when adding your second menu:

要添加第二个菜单,只需添加另一个键(菜单名称)并为数组分配一个值(输入描述)。 这是添加第二个菜单时的示例:


register_nav_menus( array(
'primary' => __( 'Primary Navigation', 'twentyten' ),
'secondary' => __( 'Secondary Navigation', 'twentyten' ),
) );

This technique can be used in creating other free themes or child themes as well. If you have any questions, feel free to ask in the comment.

该技术也可以用于创建其他免费主题或子主题。 如果您有任何疑问,请随时在评论中提问。

翻译自: https://www.wpbeginner.com/wp-tutorials/adding-a-second-menu-to-the-twenty-ten-theme/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值