Title: &#8216;folding&#8217; navigation list problem &#8211; custom code
Last modified: August 19, 2016

---

# ‘folding’ navigation list problem – custom code

 *  Resolved [dwzemens](https://wordpress.org/support/users/dwzemens/)
 * (@dwzemens)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/folding-navigation-list-problem-custom-code/)
 * I have some custom PHP written to show, in a sidebar, the navigation for the 
   site.
 *     ```
       <?php if(is_404() or is_search()) : ?>
       	<!--put here what you want to show on your 404 and searchresults pages instead of the childpages-->
       	<?php else : ?>
       	<?php
       		if($post->post_parent)  // If this is a Child page
       		$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
       		else
       		$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");  // This is a Parent page
       		if ($children) { ?>
       		<ul class="subnav">
       			<li><h2 class="menu-image"><small><em>more choices</em></small><br /><?php echo($parent_title = get_the_title($post->post_parent)); ?></h2></li>
       		<?php include("recent-news-edu.php"); ?>
       		<?php echo $children; ?>
       		</ul>
       	<?php } ?>
   
       <?php endif; ?>
       ```
   
 * The test site is located at:
    [http://gator956.hostgator.com/~dwzemens/worship/mass-times/](http://gator956.hostgator.com/~dwzemens/worship/mass-times/)
 * Here’s the client’s question that I cannot solve:
    Is it possible to reconfigure
   the way the sidebar menus show up, so that the entire section appears (like the
   entire WORSHIP section) whenever a visitor is in ANY part of the worship pages?
   For example, if I go to WORSHIP I see a full index of WORSHIP, then I click on
   SACRAMENTS and see a full index of WORSHIP, then I click on BAPTISM, and I’d 
   like to still see that full index, but I only get the SACRAMENT index.
 * Can anyone offer any help for me by a modification to this code or by suggesting
   some other method?
 * Thanks so very much for the help.

Viewing 1 replies (of 1 total)

 *  Thread Starter [dwzemens](https://wordpress.org/support/users/dwzemens/)
 * (@dwzemens)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/folding-navigation-list-problem-custom-code/#post-1209020)
 * For those interested here is how I solved the problem:
 *     ```
       <!--
       http://diggingintowordpress.com/2009/07/delicious-recipes-wordpress-page-menus/
       -->
       <?php if(is_404() or is_search()) : ?>
       	<!--put here what you want to show on your 404 and searchresults pages instead of the childpages-->
       	<?php else : ?>
       	<?php
       		if($post->post_parent)  // If this is a Child page
       			{
       				$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
       				//echo("Sub Level Menu");
       				$this_post = $post->post_parent;
       				//echo("X--.$this_post.--X");
   
       				//  http://wordpress.org/support/topic/252513?replies=5
       				$ancestors = get_post_ancestors($post);
       				$root=count($ancestors)-1;
       				//echo "root page id  is >> " . $ancestors[$root];
       				$da_child = $ancestors[$root];
   
       				// http://wordpress.org/support/topic/227954?replies=6
       				//if (in_array(854,$ancestors)) echo "--854 is an ancestor of the post";
       				// Get the entire page list from the topmost ancestore down using $da_child variable below
       				$children = wp_list_pages("title_li=&child_of=$da_child&echo=0"); // Baptism sub page
       			}
       			else
       			{
       				$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");  // This is a Parent page
       				//echo("Top Level Menu");
       			}
       		if ($children)
       			{ ?>
       				<ul class="subnav">
       				<!-- only display title for top level ancestor page -->
       				<li><h2 class="menu-image"><small><em>more choices</em></small><br /><?php echo($parent_title = get_the_title($da_child)); ?></h2></li>
       				<!--<li><h2 class="menu-image"><small><em>more choices</em></small><br />< ?php echo($parent_title = get_the_title($post->post_parent)); ?></h2></li>-->
       				<?php include("recent-news-edu.php"); ?>
       				<?php echo $children; ?>
       				<?php //echo $ancestors; ?>
       			</ul>
       	<?php } ?>
       <?php endif; ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘‘folding’ navigation list problem – custom code’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [dwzemens](https://wordpress.org/support/users/dwzemens/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/folding-navigation-list-problem-custom-code/#post-1209020)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
