0
而不是僅選中當前值,它們全部被選中。當我回顯當前值時,它顯示正確,但我似乎無法弄清楚如何讓它被選中。選擇當前下拉值 - WordPress主題選項
<?php
echo $settings['featured-one'];
$cats = get_categories();
echo '<select name="sa_options[featured-one]"><option value="select">Select</option><option value="empty">Categories</option>';
foreach($cats as $cat){
if ($cat->term_id.$cat->slug == $settings['featured-one']) $selected = 'selected="selected"';
echo '<option value="'.$cat->term_id.$cat->slug.'" '.$selected.'> - '.$cat->name.'</option>';
}
$pgs = get_pages();
echo '<option value="empty">Pages</option>';
foreach($pgs as $pg){
if ($pg->ID.$pg->post_name == $settings['featured-one']) $selected = 'selected="selected"';
echo '<option value="'.$pg->ID.$pg->post_name.'" '.$selected.'> - '.$pg->post_title.'</option>';
}
$posts = get_posts();
echo '<option value="empty">Posts</option>';
foreach($posts as $post){
if ($post->ID.$post->post_name == $settings['featured-one']) $selected = 'selected="selected"';
echo '<option value="'.$post->ID.$post->post_name.'" '.$selected.'> - '.$post->post_title.'</option>';
}
echo '</select>';
?>
檢查元素和檢查是否得到'selected = selected'? – Rikesh
每個選項都獲取selected = selected。 – lefty55104
有問題。在每個if條件之前定義'$ selected ='';'。 – Rikesh