$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' )
我的方法是否正确,还是因为上述两个条件不起作用而误会了什么?
相关文章
您无需为赋值添加三元运算符。当您的单选按钮时,它本身包含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' ];