在公共职能部门Update
此代码位于→
`public function update($new_instance, $old_instance)
$instance[\'description_box\'] = $new_instance[\'description_box\'];
在公共函数小部件中,此代码位于→public function widget($args, $instance) {
$description_box = $instance[ \'description_box\' ] ? \'true\' : \'false\';
在公共职能部门→public function form( $instance ) {
此代码位于→ <p> <input class="checkbox" type="checkbox" <?php checked( $instance[ \'description_box\' ], \'on\' ); ?> id="<?php echo $this->get_field_id( \'description_box\' ); ?>" name="<?php echo $this->get_field_name( \'description_box\' ); ?>" />
<label for="<?php echo $this->get_field_id( \'description_box\' ); ?>">Check whether to display description or not</label>
</p>
现在我想要的是,当条件为真时,即选中该框,然后执行一些代码。If ($description_box is true) {
<p>some text</p>
}
如何使用→https://codex.wordpress.org/Function_Reference/checked使现代化→
我试过用这个→
<?php if($description_box==0){ ?>
<p><</p>
<?php } ?>
但问题是,如果小部件位于两个不同的侧栏中,在一个复选框中勾选,在另一个复选框中不勾选,但在两个侧栏中的结果都是相同的,即它要么显示<p></p>
或者不基于$description_box
在中设置为0/1或真/假php
if condition
. 有什么补救办法?