Title: Help w/ Sub-Navigation Script?
Last modified: August 19, 2016

---

# Help w/ Sub-Navigation Script?

 *  [msmith29063](https://wordpress.org/support/users/msmith29063/)
 * (@msmith29063)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/help-w-sub-navigation-script/)
 * I’m currently using this script for my side sub-navigation on pages.php:
 *     ```
       <?php
       if ($post->post_parent)	{
       	$ancestors = get_post_ancestors($post->ID);
       	$root = count($ancestors) - 1;
       	$parent = $ancestors[$root];
       } else {
       	$parent = $post->ID;
       }
       $children = wp_list_pages("title_li=&child_of=". $parent ."&echo=0");
       if ($children) { ?>
       	<ul>
       		<?php print $children; ?>
       	</ul>
       <?php } ?>
       ```
   
 * How can this script be tweaked so that no children pages are shown until you 
   actually go down into one of the subcategories or sub-subcategories?
 * So you would initially see:
 * Subcategory 1
    Subcategory 2 Subcategory 3
 * If you clicked on Subcategory 2 (or any of its sub-subcategories), you would 
   see:
 * Subcategory 1
    Subcategory 2 – Sub-subcategory 1 – Sub-subcategory 2 – Sub-subcategory
   3 Subcategory 3
 * Any help would be greatly appreciated. Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [msmith29063](https://wordpress.org/support/users/msmith29063/)
 * (@msmith29063)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/help-w-sub-navigation-script/#post-1639625)
 * Can anyone help here?
 *  Thread Starter [msmith29063](https://wordpress.org/support/users/msmith29063/)
 * (@msmith29063)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/help-w-sub-navigation-script/#post-1639678)
 * Bump. Still need to address this question. Any help?
 * Subcategory = Level 2 Page
 * Sub-subcategory = Level 3 Page
 * Thank you for your time.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Help w/ Sub-Navigation Script?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 1 participant
 * Last reply from: [msmith29063](https://wordpress.org/support/users/msmith29063/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/help-w-sub-navigation-script/#post-1639678)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
