tags:

views:

23

answers:

1

How can I do code the wordpress page into dropdown list something like this Page 1 Page 2 Page 3

and then when I click submit it goes to the selected page.. .thank you so much guys in advance.. .

-idontknowhow

+1  A: 

Use get_pages to fech all the pages under the system, there's an example to do exactly what you want:

<select name="page-dropdown"
    onchange='document.location.href=this.options[this.selectedIndex].value;'> 
    <option value=""><?php echo attribute_escape(__('Select page')); ?></option> 
    <?php 
        $pages = get_pages(); 
        foreach ($pages as $pagg) {
            $option = '<option value="'.get_page_link($pagg->ID).'">';
            $option .= $pagg->post_title;
            $option .= '</option>';
            echo $option;
        }
    ?>
</select>
Adirael
Hi Adirael thanks for fast respond should I put a <form action="page"></form> to goes to selected page? sorry for my question I'm new in wordpress... thank you so much.. .
idontknowhow
Is not really necessary, this doesn't has a Go or Submit button, the second line reads: "onchange='document.location.href=this.options[this.selectedIndex].value;'" so it will automatically redirect the user to the selected page on the dropdown.
Adirael
Hi Adirael,It works great thank you so much!!
idontknowhow