以下是我的html& PHP代码。我不知道哪里出错了。但无论我选择什么选项,都会进入默认状态。就像我选择header3一样,它会转到标题默认值。有人可以帮帮我吗。感谢
HTML
<tr>
<td>Select Header</td>
<td>
<select name='meta[choose_header]'>
<option value='header_default' <?=$post->get_meta("choose_header") == "header_default" ? "selected" : "" ?> >Header Default</option>
<option value='header1' <?=$post->get_meta("choose_header") == "header1" ? "selected" : "" ?> >Header 1</option>
<option value='header2' <?=$post->get_meta("choose_header") == "header2" ? "selected" : "" ?> >Header 2</option>
<option value='header3' <?=$post->get_meta("choose_header") == "header3" ? "selected" : "" ?> >Header 3</option>
<option value='header4' <?=$post->get_meta("choose_header") == "header4" ? "selected" : "" ?> >Header 4</option>
<option value='header5' <?=$post->get_meta("choose_header") == "header5" ? "selected" : "" ?> >Header 5</option>
</select>
</td>
</tr>
PHP
<?php if ($post->get_meta("choose_header") == "header1"){ ?>
<p><?=$theme->get_option("address1")?></p>
<?} elseif ($post->get_meta("choose_header") == "header2") { ?>
<p><?=$theme->get_option("address2")?></p>
<?} elseif ($post->get_meta("choose_header") == "header3") { ?>
<p><?=$theme->get_option("address3")?></p>
<?} elseif ($post->get_meta("choose_header") == "header4") { ?>
<p><?=$theme->get_option("address4")?></p>
<?} elseif ($post->get_meta("choose_header") == "header5") { ?>
<p><?=$theme->get_option("contact_address5")?></p>
<?} elseif ($post->get_meta("choose_header") == "default") { ?>
<p><?=$theme->get_option("address_default")?></p>
<?}
else{?>
<p><?=$theme->get_option("address_default")?></p>
<?}?>
</div>
答案 0 :(得分:0)
我将代码更改为以下&amp;它开始工作了。我还是不知道出了什么问题。如果有人理解,请解释我。谢谢。
<tr>
<td>Select Header</td>
<td>
<select name='meta[choose_header]'>
<option value='header1' <?=$post->get_meta("choose_header") == "header1" ? "selected" : "" ?> >Header 1</option>
<option value='header2' <?=$post->get_meta("choose_header") == "header2" ? "selected" : "" ?> >Header 2</option>
<option value='header3' <?=$post->get_meta("choose_header") == "header3" ? "selected" : "" ?> >Header 3</option>
<option value='header4' <?=$post->get_meta("choose_header") == "header4" ? "selected" : "" ?> >Header 4</option>
<option value='header5' <?=$post->get_meta("choose_header") == "header5" ? "selected" : "" ?> >Header 5</option>
<option value='header-default' <?=$post->get_meta("choose_header") == "header-default" ? "selected" : "" ?> >Header Default</option>
</select>
</td>