wid-banner.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. add_action( 'widgets_init', 'd_banners' );
  3. function d_banners() {
  4. register_widget( 'd_banner' );
  5. }
  6. class d_banner extends WP_Widget {
  7. function d_banner() {
  8. $widget_ops = array( 'classname' => 'd_banner', 'description' => '显示一个广告(包括富媒体)' );
  9. $this->WP_Widget( 'd_banner', 'Yusi-广告', $widget_ops, $control_ops );
  10. }
  11. function widget( $args, $instance ) {
  12. extract( $args );
  13. $title = apply_filters('widget_name', $instance['title']);
  14. $code = $instance['code'];
  15. echo $before_widget;
  16. echo '<div class="d_banner_inner">'.$code.'</div>';
  17. echo $after_widget;
  18. }
  19. function form($instance) {
  20. ?>
  21. <p>
  22. <label>
  23. 广告名称:
  24. <input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $instance['title']; ?>" class="widefat" />
  25. </label>
  26. </p>
  27. <p>
  28. <label>
  29. 广告代码:
  30. <textarea id="<?php echo $this->get_field_id('code'); ?>" name="<?php echo $this->get_field_name('code'); ?>" class="widefat" rows="12" style="font-family:Courier New;"><?php echo $instance['code']; ?></textarea>
  31. </label>
  32. </p>
  33. <?php
  34. }
  35. }
  36. ?>