1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
<?php
class Ad_Rotator_Widget extends WP_Widget {
....
}
function widget($args, $instance) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
$text = $instance['text'];
$chunks = explode('<!--more-->', $text);
$chunkno = rand(0, sizeof($chunks) - 1);
echo $before_widget;
if (!empty($title)) echo $before_title . $title . $after_title;
echo '<div class="widget_ad_rotator">' . trim($chunks[$chunkno]) . '</div>';
echo $after_widget;
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
if (current_user_can('unfiltered_html'))
$instance['text'] = $new_instance['text'];
else
$instance['text'] = wp_filter_post_kses($new_instance['text']);
return $instance;
}
function form($instance) {
$instance = wp_parse_args((array)$instance, array('title' => '', 'text' => ''));
$title = strip_tags($instance['title']);
$text = format_to_edit($instance['text']);
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">
Title:
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" />
</label>
</p>
<p><label for="<?php echo $this->get_field_id('text'); ?>">HTML Text (chunks are separated with <tt><!--more--></tt>):</label></p>
<textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea>
<?php
}
}
.......
?> |
Partager