Don't be shellfish...Share on FacebookTweet about this on TwitterPin on PinterestEmail this to someone

This article define for how to create custom sub menu in wordpress.

Using the following code you can create sub menu in wordpress. for that you want to first get all detail about category using wp_get_nav_menu_items(). and after you can used our function you can get html for navigation menu item.

<?php
$page_id = get_the_ID();
$args = array(
'order' => 'ASC',
'orderby' => 'menu_order',
'post_type' => 'nav_menu_item',
'post_status' => 'publish',
'output' => ARRAY_A,
'output_key' => 'menu_order',
'nopaging' => true,
'update_post_term_cache' => false );
$header_menus = wp_get_nav_menu_items( 480, $args );

function generatePageTree($datas, $parent = 0, $depth=0)
{
if($depth > 1000) return ''; // Make sure not to have an endless recursion
if($depth==1)
$tree = '<ul class="sub_menu">';
else
$tree = '<ul>';
for($i=0, $ni=count($datas); $i < $ni; $i++){
if($datas[$i]->menu_item_parent == $parent){
$tree .= '<li>';
$tree .= '<a href="'.$datas[$i]->url.'">'.$datas[$i]->title.'</a>';
$tree .= generatePageTree($datas, $datas[$i]->ID, $depth+1);
$tree .= '</li>';
}

}
$tree .= '</ul>';
return $tree;
}
echo(generatePageTree($header_menus));
?>

create custom sub menu in wordpress

create custom sub menu in wordpress

Don't be shellfish...Share on FacebookTweet about this on TwitterPin on PinterestEmail this to someone