• I’m using the following code to display a list of child pages within a child page…

    <?php
      if($post->post_parent)
      $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");
      if ($children) { ?>
      <ul>
      <?php echo $children; ?>
      </ul>
      <?php } ?>

    It works great but I’m wondering how to adjust it so it shows up as a jump menu instead of an ordered list.

    Any help would be much appreciated.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter gjuddy

    (@gjuddy)

    ok, I’ve figured out how to list the child pages as a select menu instead of a list…(quite easy, just change wp_list_pages to wp_dropdown_pages).

    So now I’ve got this…

    <?php
      if($post->post_parent)
      $children = wp_dropdown_pages("title_li=&child_of=".$post->post_parent."&echo=0");
      else
      $children = wp_dropdown_pages("title_li=&child_of=".$post->ID."&echo=0");
      if ($children) { ?>
      <ul>
      <?php echo $children; ?>
      </ul>
      <?php } ?>

    Can anyone tell me how to turn this list into a jump menu…so when any one of the items in the list are selected, you are forwarded to that page.

    Thread Starter gjuddy

    (@gjuddy)

    So now I’ve got it figured out…

    <form action="<?php bloginfo('url'); ?>/" method="get">
    <?php
    if($post->post_parent)
    $select = wp_dropdown_pages("title_li=&child_of=".$post->post_parent."&echo=0");
    else
    $select = wp_dropdown_pages("title_li=&child_of=".$post->ID."&echo=0");
    $select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
    echo $select;
    ?>
    </form>

    The above code pulls all the sub pages with the same parent as the live page and puts them in a jump menu.

    Can anyone tell me how to utilize the “selected” parameter to have the menu default to whatever page is live. Currently it always just lists the first item in the menu…

    Don’t know if this helps, but I used the following code…

    <form action="<?php bloginfo('url'); ?>" method="get">
    <?php
    echo '<!-- ';
    $select = wp_dropdown_pages('sort_column=menu_order');
    echo ' -->';
    $select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
    echo $select;
    ?>
    </form>

    I couldn’t stop the first instance of wp_dropdown_pages printing the form so I used comment tags either side. So it doesn’t show on the page, but does in the source code. Oh well…

    It still just lists the first item in the menu…

    I’m having the exact same issue. I’ve tried adding this line of code which will appear at the top of the list. I’m using a dual dropdown though.

    $select = wp_dropdown_pages('sort_column=menu_order&show_option_none=Select a Topic');

    In the above example, “Select a Topic” appears at the top of the list and is shown.

    I’ve tried replacing with “Select a Topic” with a bunch of other variables to display the current page title.

    '.$page.'

    Or something like that should work, but I haven’t figured it out out.

    All you have to do is to re-order the list to force the current page to appear first or use the show_option_none code.

    Thread Starter gjuddy

    (@gjuddy)

    Finally got it figured out…

    <form action="<?php bloginfo('url'); ?>/" method="get">
    <?php
    if($post->post_parent)
    $select = wp_dropdown_pages("sort_column=menu_order&selected=".$post->ID."&title_li=&child_of=".$post->post_parent."&echo=0");
    else
    $select = wp_dropdown_pages("title_li=&child_of=".$post->ID."&echo=0");
    $select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
    echo $select;
    ?>
    </form>

    Thanks ensignkid for the sort column tip as well.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘sub pages in a jump menu’ is closed to new replies.