kreamweb
2/9/2013 - 12:15 PM

[Wordpress] Display a list of pages from with all subchilds. A complete dynamic menu

[Wordpress] Display a list of pages from with all subchilds. A complete dynamic menu

<?php
  	$a=get_post_ancestors($post->ID,'page');
	if(empty($a)){
        	//I'm in the root page
		$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
		$title=$post->post_title;
        	$id=$post->ID;
	}else{
        	//I'm in a sub page
		$last=array_pop($a);
		$children = wp_list_pages("title_li=&child_of=".$last."&echo=0");
		$post_parent=get_post($last);
		$title=$post_parent->post_title;
        	$id=$post_parent->ID;
	}

 	if ($children) { ?>
	<div class="title-menu"><a href="<?php echo get_permalink($id) ?>"><?php echo $title ?></a></div>
	<div id="side-menu">
	    <ul><?php echo $children; ?></ul>
	 </div>