简体   繁体   English

将自定义沃克和自定义ul类应用于Wordpress中的特定菜单

[英]Apply custom walker and custom ul class to specific menus in wordpress

I am trying to apply a custom walker and class to specific menus. 我正在尝试将自定义沃克和类应用于特定菜单。 This is because my class for the UL is different depending on menu locations. 这是因为根据菜单位置,我在UL上的课程有所不同。

I have correctly registered menu location in the backend, and applied each menu to their location (Contact to contact, About to about etc.) 我已经正确注册在后台菜单位置,并应用于每个菜单中的位置(联系联系,关于约等)

This is what I have so far but it doesn't seem to target my menu 这是我到目前为止的内容,但似乎没有针对我的菜单

function my_custom_walker( $args ) {
$menu_locations = get_nav_menu_locations();

if ($menu_locations == 'contact') {

$args['walker'] = new sidemenu_walker();
$args['menu_class'] = 'mycustomclassforul';

}
return $args;
}
add_filter( 'wp_nav_menu_args', 'my_custom_walker' );

Managed to do it with this 设法做到这一点

function my_custom_walker( $args ) {

$menu = $args['menu'];
if($menu->name = 'contact' || $menu->name = 'about' )  
{
    $args['container'] = '';
    $args['menu_class'] = 'mycustomclassforul';
    $args['walker'] = new sidemenu_walker();
}
return $args;

}
add_filter( 'wp_nav_menu_args', 'my_custom_walker' );

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

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