wordpress show selected item
I am pulling certain pages using query_posts to populate a dropdown menu.
lets assume the list populate the following fields
option1, option2, option3 and option4
Now if I have selected option3
and my page changes to this, how do I display this as the selectedIndex?
<select name="speedC" id="speedC"
onchange=开发者_如何学Go'document.location.href=this.options[this.selectedIndex].value;'>
<option value="">
<?php echo attribute_escape(__('Välj en från listan')); ?></option>
<?php
$pages = get_pages('include=11,13,15,17,38');
foreach ($pages as $pagg) {
$option = '<option value="'.get_page_link($pagg->ID).'">';
$option .= $pagg->post_title;
$option .= '</option>';
echo $option;
} ?>
</select>
You want to use the Wordpress function is_page()
is_page('id')
Where 'id' is the id that you already have fetched. For more information, check the wordpress codex site
EDIT: I'm not too sure about the syntax here, but something like this might get you up and running:
<select name="speedC" id="speedC"
onchange='document.location.href=this.options[this.selectedIndex].value;'>
<option value="">
<?php echo attribute_escape(__('Välj en från listan')); ?></option>
<?php
$pages = get_pages('include=11,13,15,17,38');
foreach ($pages as $pagg) {
$option = '<option value="'.get_page_link($pagg->ID).'"';
if(is_page($pagg->ID)){
$option .= "SELECTED "
}
$option .= ">".$pagg->post_title;
$option .= '</option>';
echo $option;
} ?>
</select>
精彩评论