$instance['what_to_check_for'] = sanitize_text_field($new_instance['what_to_check_for']);
现在我试图通过三元运营商做点什么→
$description_radio_box = $instance[ 'what_to_check_for' ] ? 'check_for_counter' : 'check_for_image';
基本上我想找个条件→
<?php if( $description_radio_box == 'check_for_counter' ){ ?>
或
<?php if( $description_radio_box == 'check_for_image' )
我的方法是正确的还是我错了,因为上述两种情况都不起作用?
答案 0 :(得分:1)
您无需为分配值添加三元运算符。作为您的单选按钮,它自身包含check_for_counter
或check_for_image
等值。只需将单选按钮值指定给$description_radio_box
变化
$description_radio_box = $instance[ 'what_to_check_for' ] ? 'check_for_counter' : 'check_for_image';
要
$description_radio_box = $instance[ 'what_to_check_for' ];