functions.php PHP カスタムヴィジェット めも

/* オリジナル ウィジェット */
class MyWidgetItem extends WP_Widget {
function MyWidgetItem() {
parent::WP_Widget(false, $name = '会社情報');
}
function widget($args, $instance) {
extract( $args );

$title = apply_filters( 'widget_title', $instance['title'] ); #会社名
$title2 = apply_filters( 'widget_title2', $instance['title2'] ); # 郵便番号
$title3 = apply_filters( 'widget_title3', $instance['title3'] ); #住所
$title4 = apply_filters( 'widget_title4', $instance['title4'] ); #TEL
$title5 = apply_filters( 'widget_title5', $instance['title5'] ); #FAX
$title6 = apply_filters( 'widget_title6', $instance['title6'] ); #営業時間

$body = apply_filters( 'widget_body', $instance['body'] );
?>

<p <?php echo 'id="company"'; ?>>
<?php if($title) ?>
<?php echo $title; ?>
</p>

<li <?php echo 'id="address"'; ?> >
<?php if($title2 || $title3)?>
<?php echo $title2; ?> <?php echo $title3 ?>
</li>

<p <?php echo 'id="tel-fax"'; ?>>
<?php if($title4 || $title5) ?>
<?php echo $title4; ?> <?php echo $title5; ?>
</p>

<p <?php echo 'id="eigyou"' ?>>
<?php if($title6) ?>
<?php echo $title6; ?>
</p>
<?php
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['title2'] = strip_tags($new_instance['title2']);
$instance['title3'] = strip_tags($new_instance['title3']);
$instance['title4'] = strip_tags($new_instance['title4']);
$instance['title5'] = strip_tags($new_instance['title5']);
$instance['title6'] = strip_tags($new_instance['title6']);

$instance['body'] = trim($new_instance['body']);
return $instance;
}
function form($instance) {
$title = esc_attr($instance['title']);
$title2 = esc_attr($instance['title2']);
$title3 = esc_attr($instance['title3']);
$title4 = esc_attr($instance['title4']);
$title5 = esc_attr($instance['title5']);
$title6 = esc_attr($instance['title6']);

$body = esc_attr($instance['body']);
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">
<?php _e('会社名:'); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</p>

<p>
<label for="<?php echo $this->get_field_id('title2'); ?>">
<?php _e('郵便番号:'); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id('title2'); ?>" name="<?php echo $this->get_field_name('title2'); ?>" type="text" value="<?php echo $title2; ?>" />
</p>

<p>
<label for="<?php echo $this->get_field_id('title3'); ?>">
<?php _e('住所:'); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id('title3'); ?>" name="<?php echo $this->get_field_name('title3'); ?>" type="text" value="<?php echo $title3; ?>" />
</p>

<p>
<label for="<?php echo $this->get_field_id('title4'); ?>">
<?php _e('電話番号:'); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id('title4'); ?>" name="<?php echo $this->get_field_name('title4'); ?>" type="text" value="<?php echo $title4; ?>" />
</p>


<p>
<label for="<?php echo $this->get_field_id('title5'); ?>">
<?php _e('FAX番号:'); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id('title5'); ?>" name="<?php echo $this->get_field_name('title5'); ?>" type="text" value="<?php echo $title5; ?>" />
</p>

<p>
<label for="<?php echo $this->get_field_id('title6'); ?>">
<?php _e('営業時間:'); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id('title6'); ?>" name="<?php echo $this->get_field_name('title6'); ?>" type="text" value="<?php echo $title6; ?>" />
</p>

<p>
<label for="<?php echo $this->get_field_id('body'); ?>">
<?php _e('サイトに表示されるコンテンツ:'); ?>
</label>
<textarea class="widefat" rows="16" colls="20" id="<?php echo $this->get_field_id('body'); ?>" name="<?php echo $this->get_field_name('body'); ?>">
<?php echo $body; ?>
</textarea>
</p>
<?php
}
}
add_action('widgets_init', create_function('', 'return register_widget("MyWidgetItem");'));