javascript - wordpress show selected item -
i pulling pages using query_posts populate dropdown menu.
lets assume list populate following fields
option1, option2, option3 , option4
now if have selected option3
, page changes this, how display selectedindex?
<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 $pagg) { $option = '<option value="'.get_page_link($pagg->id).'">'; $option .= $pagg->post_title; $option .= '</option>'; echo $option; } ?> </select>
you want use wordpress function is_page()
is_page('id')
where 'id' id have fetched. more information, check wordpress codex site
edit: i'm not sure syntax here, might , 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 $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>
Comments
Post a Comment