2

I have a dropdown menu of pages, but after I go to a page selected, let's say "About us", the default title button of dropbown is the title of the page, "About us", so i want the title/default option to be "Please select a page" or something like that.

My code is this:

wp_dropdown_pages("title_li=&depth=1&sort_column=menu_order&child_of=".$post->post_parent."&echo=0&selected=$currPage");

What i'm doing wrong or how my code should look?

1

I would suggest, that you switch from "URl query argument" style to arrays. This is a "feature" that is more a left over on some functions that is only available for backwards compatibility reasons than anything else.

Here's a reworked version of your current arguments:

wp_dropdown_pages( array(
    'title_li'    => '',
    'depth'       => TRUE,               // originally: 1,
    'sort_column' => 'menu_order',
    'child_of'    => $post->post_parent,
    'echo'        => FALSE,              // originally: 0,
    'selected'    => $currPage,
) );

Now I wonder how you managed to display that dropdown/select element when echo was set to 0/false and no echo/print was prepended to that statement. If you are just adding it to your template like this, you better set echo to TRUE.

From looking at the selected argument (and as you can read in the docs in Codex), this is the argument that chooses what element currently is selected. As you are setting it to $currPage, which I assume that it contains the current page slug, it shows you exactly that. To "fix" your problem, simply set it to an empty string ''.

About the first/non-selected value: You can set that with the show_option_none argument

'show_option_none' => 'Please select a page',
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.