wp オリジナルウィジェット サイドお知らせ
/* ------------------オリジナル ウィジェット サイドバー お知らせ ------------------
------------------------ ----------------*/
class MyWidgetItem2 extends WP_Widget {
function MyWidgetItem2() {
parent::WP_Widget(false, $name = 'サイド お知らせ');
}
function widget($args, $instance) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] ); #会社名
?>
<h3 class="side_title"><?php echo $title; ?></h3>
<ul class="side_news">
<?php
$args = array(
'posts_per_page' => 3,
);
$my_query = new WP_Query($args);
while($my_query->have_posts()): $my_query->the_post();?>
<li><a href="<?php the_permalink(); ?>"><spna class="side_news"><?php the_time('Y年m月d日'); ?></spna>
<span class="side_news_title"><?php the_title(); ?></span>
</a>
</li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</ul>
<?php
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
return $instance;
}
function form($instance) {
$title = esc_attr($instance['title']);
?>
<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>
<?php
}
}
add_action('widgets_init', create_function('', 'return register_widget("MyWidgetItem2");'));