我有一个问题,我知道为什么,但我找不到解决方案,也找不到解决方法!
问题是在菜单中使用自定义预览时,实时预览编辑不起作用,这是因为我没有使用wp_nav_menu 函数,而我使用wp_get_nav_menu_items 因为它更具自定义性,我需要按名称为每个菜单项插入不同的图标,如下面的代码所示:
// Get the nav menu based on $menu_name (same as \'theme_location\' or \'menu\' arg to wp_nav_menu)
// This code based on wp_nav_menu\'s code to get Menu ID from menu slug
if ( is_front_page() )
$menu_name = \'home\';
else
$menu_name = \'primary\';
if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menu_items = wp_get_nav_menu_items($menu->term_id);
$menu_list = \'<ul class="menu nav list-unstyled nav-stacked" role="tablist" id="menu-nav-menu">\';
foreach ( (array) $menu_items as $key => $menu_item ) {
$title = $menu_item->title;
$id = $menu_item->ID;
$title = strtolower($title);
$title = rtrim($title);
$url = $menu_item->url;
$active = \'\';
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if($url == $actual_link)
{
$active = \'active\';
}
else {
$active = \'\';
}
switch ($title) {
case \'profile\':
$nav_icon = \'fa-user\';
break;
case \'resume\':
$nav_icon = \'fa-file\';
break;
case \'portfolio\':
$nav_icon = \'fa-paint-brush\';
break;
case \'plans\':
$nav_icon = \'fa-map-signs\';
break;
case \'blog\':
$nav_icon = \'fa-pencil\';
break;
case \'testimonials\':
$nav_icon = \'fa-quote-left\';
break;
case \'clients\':
$nav_icon = \'fa-users\';
break;
case \'contact\':
$nav_icon = \'fa-envelope\';
break;
default:
$nav_icon = \'fa-eercast\';
break;
}
$menu_list .= "<li id=\'menu-item-{$id}\' class=\'{$active} menu-item menu-item-type-custom menu-item-object-custom menu-item-{$id}\'><a href=\'{$url}\'><i class=\'fa {$nav_icon}\'></i> {$title}</a></li>";
}
$menu_list .= \'<li><form method="get" action="\'.site_url(\'/\').\'"><input type="search" name="s" class="form-control" placeholder="Search..."></form></li>\';
$menu_list .= \'</ul>\';
} else {
$menu_list = \'<ul class="nav list-unstyled nav-stacked"><li style="color: #fff">Menu "\' . $menu_name . \'" <strong>empty!</strong>.</li></ul>\';
}
// $menu_list now ready to output
echo $menu_list;
因此,如果中间有任何解决方案,如我可以插入图标(仅使用代码,因为我不能使用插件),并启用快速预览定制器,我将不胜感激。