我有以下array
:
$instance_defaults = array(
'title' => 'Popular Posts',
'num_posts' => $instance['num_posts']
);
我注意到了
num_posts
是未定义的索引。试图使用array_key_exist
,但没有成功删除通知的任何想法?
public function form( $instance ) {
$instance_defaults = array(
'title' => 'Popular Posts',
'num_posts' => $instance['num_posts']
);
$instance = wp_parse_args( $instance, $instance_defaults );
$num_posts = esc_attr( $instance['num_posts'] );
?>
<p>
<label for="<?php echo $this->get_field_id('num_posts'); ?>">
<?php _e( "Number of posts to show: ", 'dx-posts-widgets'); ?>
</label>
<input class="widefat"
id="<?php echo $this->get_field_id('num_posts'); ?>"
name="<?php echo $this->get_field_name('num_posts'); ?>"
type="text" value="<?php echo $num_posts; ?>" />
</p>
<?php
}