是否有方法在功能中组合多个菜单。使用wp\\u nav\\u menu\\u items()的php文件?我需要将第二个菜单连接到主菜单。网站标题中有两个单独的菜单。一个是下拉菜单,另一个是汉堡。使用移动设备时,下拉列表不好。我需要将下拉菜单(菜单2)中的项目添加到主菜单(汉堡)。
下面是我当前的设置。如你所见,我已经在菜单中添加了社交和公司信息。现在我需要添加第二个菜单。
function add_social_to_wp_menu ( $items, $args ) {
if ( \'on\' === et_get_option( \'divi_show_facebook_icon\', \'on\' ) ) :
$social_icons .= \'<span class="et-social-icon et-social-facebook">
<a href="\'.esc_url( et_get_option( \'divi_facebook_url\', \'#\' ) ).\'" class="icon">
</a>
</span>\';
endif;
if ( \'on\' === et_get_option( \'divi_show_twitter_icon\', \'on\' ) ) :
$social_icons .= \'<span class="et-social-icon et-social-twitter">
<a href="\'.esc_url( et_get_option( \'divi_twitter_url\', \'#\' ) ).\'" class="icon">
</a>
</span>\';
endif;
if ( \'on\' === et_get_option( \'divi_show_google_icon\', \'on\' ) ) :
$social_icons .= \'<span class="et-social-icon et-social-google-plus">
<a href="\'.esc_url( et_get_option( \'divi_google_url\', \'#\' ) ).\'" class="icon">
</a>
</span>\';
endif;
if ( \'on\' === et_get_option( \'divi_show_instagram_icon\', \'on\' ) ) :
$social_icons .= \'<span class="et-social-icon et-social-instagram">
<a href="\'.esc_url( et_get_option( \'divi_instagram_url\', \'#\' ) ).\'" class="icon">
</a>
</span>\';
endif;
if ( \'on\' === et_get_option( \'divi_show_youtube_icon\', \'on\' ) ) :
$social_icons .= \'<span class="et-social-icon et-social-youtube">
<a href="\'.esc_url( et_get_option( \'divi_youtube_url\', \'#\' ) ).\'" class="icon">
</a>
</span>\';
endif;
if ( \'on\' === et_get_option( \'divi_show_rss_icon\', \'on\' ) ) :
$et_rss_url = \'\' !== et_get_option( \'divi_rss_url\' )
? et_get_option( \'divi_rss_url\' )
: get_bloginfo( \'rss2_url\' );
$social_icons .= \'<span class="menu-item et-social-icon et-social-rss">
<a href="\'.esc_url( $et_rss_url ).\'" class="icon">
</a>
</span>\';
endif;
if( \'main-menu\' === $args -> menu ) {
$items .= \'<li class="menu-item company-info">\'.do_shortcode(\'[show-company-info]\').\'</li>\';
$items .= \'<li class="menu-item social-networks">\'.$social_icons.\'</li>\';
}
return $items;
}
add_filter(\'wp_nav_menu_items\',\'add_social_to_wp_menu\',10,2);
SO网友:Jason
感谢上帝,我为其他遇到这个问题的人找到了一个解决方案。我从Wordpress codex中获取了这个函数,并对其进行了修改以满足我的需要
function get_menu($menu_name) {
$menu_items = wp_get_nav_menu_items($menu_name);
$menu_list = \'\';
$count = 0;
$submenu = false;
foreach( $menu_items as $menu_item ) {
$link = $menu_item->url;
$title = $menu_item->title;
if ( !$menu_item->menu_item_parent ) {
$parent_id = $menu_item->ID;
if(!empty($menu_items[$count + 1]) && $menu_items[ $count + 1 ]->menu_item_parent == $parent_id ) { //Checking for child
$menu_list .= \'<li class="menu-item menu-item-has-children"><a href="\'.$link.\'">\'.$title.\'</a>\';
}else{
$menu_list .= \'<li class="menu-item"><a href="\'.$link.\'">\'.$title.\'</a>\';
}
}
if ( $parent_id == $menu_item->menu_item_parent ) {
if ( !$submenu ) {
$submenu = true;
$menu_list .= \'<ul class="sub-menu">\';
}
$menu_list .= \'<li class="menu-item"><a href="\'.$link.\'">\'.$title.\'</a></li>\';
if(empty($menu_items[$count + 1]) || $menu_items[ $count + 1 ]->menu_item_parent != $parent_id && $submenu) {
$menu_list .= \'</ul>\';
$submenu = false;
}
}
if (empty($menu_items[$count + 1]) || $menu_items[ $count + 1 ]->menu_item_parent != $parent_id ) {
$menu_list .= \'</li>\';
$submenu = false;
}
$count++;
}
return $menu_list;
}
然后,我从菜单过滤器中调用了这个函数(参见上面的函数),如下所示。
if( \'main-menu\' === $args -> menu ) {
$items .= $fcs_menu = get_menu(\'SECOND MENU NAME GOES HERE\');
$items .= \'<li class="menu-item company-info">\'.do_shortcode(\'[show-company-info]\').\'</li>\';
$items .= \'<li class="menu-item social-networks">\'.$social_icons.\'</li>\';
}