Elementor Header & Footer Builder 制作wordpress的头部和尾部
参考静态模板:https://sc.chinaz.com/moban/240419393850.htm
因为菜单在网站的头部。
如果要自定义一个网站头部,首先要学会自定义菜单。
pre( wp_get_nav_menus() ); // 通过这个可以查看有哪几个菜单。
$menuLocations = get_nav_menu_locations();
pre($menuLocations);
然后参考这里的代码: https://developer.wordpress.org/reference/functions/wp_get_nav_menu_items/
https://codecopy.cn/post/5l5vik
function wp_get_nested_menu_array($current_menu) {
$array_menu = wp_get_nav_menu_items($current_menu);
$menu = array();
foreach($array_menu as $m) {
if (empty($m -> menu_item_parent)) {
$menu[$m -> ID] = array();
$menu[$m -> ID]['ID'] = $m -> ID;
$menu[$m -> ID]['title'] = $m -> title;
$menu[$m -> ID]['url'] = $m -> url;
$menu[$m -> ID]['children'] = array();
}
}
$submenu = array();
foreach($array_menu as $m) {
if ($m -> menu_item_parent) {
$submenu[$m -> ID] = array();
$submenu[$m -> ID]['ID'] = $m -> ID;
$submenu[$m -> ID]['title'] = $m -> title;
$submenu[$m -> ID]['url'] = $m -> url;
$submenu[$m -> ID]['parent'] = $m -> menu_item_parent;
if (isset($submenu[$m -> menu_item_parent])) {
$submenu[$m -> menu_item_parent]['children'][$m -> ID] = $submenu[$m -> ID];
$mainparentid = $submenu[$m -> menu_item_parent]['parent'];
$menu[$mainparentid]['children'][$m -> menu_item_parent] = $submenu[$m -> menu_item_parent];
} else {
$menu[$m -> menu_item_parent]['children'][$m -> ID] = $submenu[$m -> ID];
}
}
}
return $menu;
}
$arr = wp_get_nested_menu_array(3);
pre($arr);