我具有以下复选框形式:
<p>
<label class="mtt" for="serie_mark"><h1><?php _e( 'Options', 'randomtheme' ); ?></h1></label>
<input type="radio" name="code_name" id="supi1" value="supi1" <?php echo ( series_get_meta( 'code_name' ) === 'supi1' ) ? 'checked' : ''; ?>>
<label for="supi1"><?php _e( 'Option 1', 'randomtheme' ); ?></label><br>
<input type="radio" name="code_name" id="pishti6" value="pishti6" <?php echo ( series_get_meta( 'code_name' ) === 'pishti6' ) ? 'checked' : ''; ?>>
<label for="pishti6"><?php _e( 'Option 2', 'randomtheme' ); ?></label><br>
<input type="radio" name="code_name" id="recky2" value="recky2" <?php echo ( series_get_meta( 'code_name' ) === 'recky2' ) ? 'checked' : ''; ?>>
<label for="recky2"><?php _e( 'Option 3', 'randomtheme' ); ?></label><br>
</p>
if ( isset( $_POST['code_name'] ) )
update_post_meta( $post_id, 'code_name', esc_attr( $_POST['code_name'] ) );
如果选中了某个复选框,我可以使用以下脚本来显示消息:
<?php if($testing = series_get_meta('code_name')) {
if ($testing == 'supi1') {
echo 'My text';
} elseif ($testing == 'pishti6') {
echo 'Another text';
} elseif ($testing == 'recky2') {
echo 'Some other text';
} else {
echo 'This is the default text for nothing selected';
} } ?>
一切正常,除了一件事外,它确实会注册并显示消息...如果未选中复选框,则不会显示默认消息。任何想法如何做到这一点?谢谢。
答案 0 :(得分:1)
您需要更改if条件
if($testing = series_get_meta('code_name')) {
if ($testing == 'supi1') {
echo 'My text';
} elseif ($testing == 'pishti6') {
echo 'Another text';
} elseif ($testing == 'recky2') {
echo 'Some other text';
}
} else {
echo 'This is the default text for nothing selected';
}