function mythemes_get_menu_childrens($id) { global $mythemes_curr_ancestor; $pages = get_posts(array('post_type' => 'page', 'order' => 'ASC', 'post_parent' => $id)); $rett = ''; if (!empty($pages)) { $rett = '<ul class="sub-menu">'; foreach ($pages as $p => $item) { $classes = ''; if (is_page($item->ID)) { $classes = 'current-menu-item'; $mythemes_curr_ancestor = true; } $submenu = mythemes_get_menu_childrens($item->ID); if (!empty($submenu)) { $classes .= 'menu-item-has-children'; if ($mythemes_curr_ancestor) { $classes .= ' current-menu-ancestor'; } } $rett .= '<li class="menu-item ' . esc_attr($classes) . '">'; $rett .= '<a href="' . esc_url(get_permalink($item->ID)) . '" title="' . mythemes_post::title($item->ID, true) . '">' . mythemes_post::title($item->ID) . '</a>'; $rett .= $submenu; $rett .= '</li>'; } $rett .= '</ul>'; } return $rett; }
} else { $pages = get_posts(array('numberposts' => 7, 'post_type' => 'page', 'order' => 'ASC', 'post_parent' => 0)); if (!empty($pages)) { echo '<div class="nav-wrapper">'; echo '<ul class="mythemes-menu">'; global $mythemes_curr_ancestor; foreach ($pages as $p => $item) { $classes = ''; $mythemes_curr_ancestor = false; if ($item->post_parent > 0) { continue; } if (is_page($item->ID)) { $classes = 'current-menu-item'; } $submenu = mythemes_get_menu_childrens($item->ID); if (!empty($submenu)) { $classes .= 'menu-item-has-children'; if ($mythemes_curr_ancestor) { $classes .= ' current-menu-ancestor'; } } echo '<li class="menu-item ' . esc_attr($classes) . '">'; echo '<a href="' . esc_url(get_permalink($item->ID)) . '" title="' . mythemes_post::title($item->ID, true) . '">' . mythemes_post::title($item->ID) . '</a>'; echo $submenu; echo '</li>'; } echo '</ul>'; echo '</div>'; } }