Just a small example of how to build custom menu output in WordPress.
$menu_args = array('menu' => 'Main menu', 'echo' => 0) ; $menu_string = wp_nav_menu($menu_args); $xml = new SimpleXMLElement($menu_string); $out = false; foreach ($xml->ul[0] as $li) { $classes = array('current-page-ancestor', 'current-menu-item', 'current-menu-parent'); if (strstr($li['class'], 'current-page-ancestor') || strstr($li['class'], 'current-menu-item') || strstr($li['class'], 'current-menu-parent')) { $out = $li->ul; $i = 0; if (isset($out->li) && !empty($out->li)) { $out['id'] = 'sub_menu'; $out['class'] = 'clear'; foreach ($out->li as $li_sub) { if (!strstr($li_sub['class'], 'current-page-ancestor') && !strstr($li_sub['class'], 'current-menu-item') && !strstr($li_sub['class'], 'current-menu-parent')) { unset($out->li[$i]->ul); } $i++; } } break;; } } if (!empty($out)) { echo $out->asXML(); }
Leave a Reply
You must be logged in to post a comment.