Sub-navigation Drill-Down Menu

Create a menu that drills down to subpages as they exist.

<ul class="top_menu"><?php
		
		global $post;
		
		$ancestors = get_post_ancestors($page);
		
		$theparent = $ancestors[0];
		$oneup = $ancestors[1];
		$lastlevel = $ancestors[2];
		
		if (is_page( ) || is_single() || is_search() ) {
			 $page = $post->ID;
			 if ($post->post_parent) {
			   
			   $page = $post->post_parent;
			 }
		}
		
		
		$children = wp_list_pages('title_li=&echo=0&depth=1&child_of=' . $post->ID);
		$sub = wp_list_pages('title_li=&echo=0&depth=1&child_of=' . $post->post_parent);
		$twolevels = wp_list_pages('title_li=&echo=0&depth=0&child_of=' . $theparent);
		
		if ($lastlevel) {
			echo $twolevels;
		}
		
		 elseif ($children) {
		  	
		   echo $children;
		 }
		
		 elseif ($sub) {
			 echo $sub;
		 }
	
	
	//	echo wp_list_pages('title_li=&echo=0&depth=2&sort_column=menu_order');

	
	?></ul><!-- .top_menu -->

 

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.