Welcome to W3 Relations, We are a Digital Service Provider Company with Over 3 Years of Experience. Our Services Are Graphics Design, Web Design, Web Development, Digital Marketing.
<?php $menu_name = 'primary'; $locations = get_nav_menu_locations(); $menu = wp_get_nav_menu_object( $locations[ $menu_name ] ); $menuitems = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) ); $count = 0; $submenu = false; foreach( $menuitems as $item ): // set up title and url $title = $item->title; $link = $item->url; // item does not have a parent so menu_item_parent equals 0 (false) if ( !$item->menu_item_parent ): // save this id for later comparison with sub-menu items $parent_id = $item->ID; ?> <li class="nav-item"> <a class="nav-link text-white" href="<?php echo $link; ?>"><?php echo $title; ?></a> <?php endif; ?> <?php if ( $parent_id == $item->menu_item_parent ): ?> <?php if ( !$submenu ): $submenu = true; ?> <ul class="navbar-nav ml-auto sub-menu"> <?php endif; ?> <li class="nav-item"> <a href="<?php echo $link; ?>" class="nav-link text-white"><?php echo $title; ?></a> </li> <?php if ( $menuitems[ $count + 1 ]->menu_item_parent != $parent_id && $submenu ): ?> </ul> <?php $submenu = false; endif; ?> <?php endif; ?> <?php if ( $menuitems[ $count + 1 ]->menu_item_parent != $parent_id ): ?> </li> <?php $submenu = false; endif; ?> <?php $count++; endforeach; ?>
Submit Now