Jump Menu of Child Pages for Wordpress

Here is a small bit of code to place on your page.php template. If the page id is the parent page that has child pages, this code will generate a dropdown menu of those children only on the pages that meet that criteria. This allows you to grab each child page's attributes and output them as you please....whether it be an ordered list with or without links, or in a "<select>" menu or whatever you like. wp_list_pages doesn't give you the hands on ability to edit display results like this...yet. At the top of the page you can put this code to figure out what page you are on to determine the parent page
if ($post->post_parent) {
        $parent = $ancestors[$root];
        } else {
        $parent = $post->ID;    
Then you can place this code inside of the loop to determine whether or not to show the jump menu of child pages
if ($parent == '1') { // Check to see if we are on a page that should show this menu
echo '<select onchange="window.open(this.options[this.selectedIndex].value,'_top')">';
echo '<option> :: View Child Page :: </option>';
$pages = get_posts('post_type=page&post_parent=1&numberposts=-1&orderby=menu_order&order=ASC');
foreach ($pages as $pgs) {
echo "<option value="/" . $pgs->post_name . "/">" . $pgs->post_title . "</option>n";
echo '<option value="/wordpress/parent-page/">View Parent Page</option>'; // OPTIONAL TO LINK BACK TO PARENT PAGE                                   
echo '</select>'";
VIEW EXAMPLE Note: if you go to the "About" page, the menu disappears as it is desired.
Post a comment
  1. Matt Price

    Hi Can you tell me on which line you are receiving the error? Thanks Matt

  2. Carina

    I keep getting this error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'

Real Time Web Analytics ^