Shoora
5/31/2013 - 4:36 PM

Instead of wp_list_pages where all children and grandchildren of the current page are listed out this method lists the parent page, siblings

Instead of wp_list_pages where all children and grandchildren of the current page are listed out this method lists the parent page, siblings of the current page (in menu order) and when it gets to the current page it lists out the children.

<?php /* Not as simple as it sounds */ ?>
<div class="side-nav">
	<div class="holder">
		<ul>
			<?php
			if (isset($post->post_parent) && $post->post_parent > 0) {
				$permalink = get_permalink($post->post_parent);
				$parent_title = get_the_title($post->post_parent);
				print('<li class="page_item page-parent"><a href="'.$permalink.'">'.$parent_title.'</a></li>');
				$parent = $post->post_parent;
			} else {
				$parent = $post->ID;
			}
			$page_array = array();
			$pagers = get_pages(array('sort_column' => 'menu_order', 'hierarchical'=> 0, 'child_of' => $post->post_parent, 'parent' => $post->post_parent));
			foreach ($pagers as $pager) {
				$permalink = get_permalink($pager->ID);
				$class = "page_item page-item-".$pager->ID;
				if ($post->ID == $pager->ID) {
					$class .= " current_page_item";
				}
				print('<li class="'.$class.'"><a href="'.$permalink.'">'.$pager->post_title.'</a>');
			
			
				if ($post->ID == $pager->ID) {
					print('<ul>');
					$children = get_pages(array('sort_column' => 'menu_order', 'hierarchical'=> FALSE, 'child_of' => $pager->ID, 'parent' => $pager->ID));
					//$children = get_page_children( $pager->ID, $pagers );
					foreach ($children as $child) {
						$permalink = get_permalink($child->ID);
						$class = "page_item page-item-".$child->ID;
						print('<li class="'.$class.'"><a href="'.$permalink.'">'.$child->post_title.'</a></li>');
					}
					print('</ul>');
			
				}
				print('</li>');
			}
			?>
		</ul>
	</div>
</div>