wid-textbanner.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. add_action( 'widgets_init', 'd_textbanners' );
  3. function d_textbanners() {
  4. register_widget( 'd_textbanner' );
  5. }
  6. class d_textbanner extends WP_Widget {
  7. function d_textbanner() {
  8. $widget_ops = array( 'classname' => 'd_textbanner', 'description' => '显示一个文本特别推荐' );
  9. $this->WP_Widget( 'd_textbanner', 'Yusi-特别推荐', $widget_ops, $control_ops );
  10. }
  11. function widget( $args, $instance ) {
  12. extract( $args );
  13. $title = apply_filters('widget_name', $instance['title']);
  14. $tag = $instance['tag'];
  15. $content = $instance['content'];
  16. $link = $instance['link'];
  17. $style = $instance['style'];
  18. $blank = $instance['blank'];
  19. $lank = '';
  20. if( $blank ) $lank = ' target="_blank"';
  21. echo $before_widget;
  22. echo '<a class="'.$style.'" href="'.$link.'"'.$lank.'>';
  23. echo '<div class="title"><h2>'.$tag.'</h2></div>';
  24. echo '<h3>'.$title.'</h3>';
  25. echo '<p>'.$content.'</p>';
  26. echo '</a>';
  27. echo $after_widget;
  28. }
  29. function form($instance) {
  30. ?>
  31. <p>
  32. <label>
  33. 名称:
  34. <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" />
  35. </label>
  36. </p>
  37. <p>
  38. <label>
  39. 描述:
  40. <textarea id="<?php echo $this->get_field_id('content'); ?>" name="<?php echo $this->get_field_name('content'); ?>" class="widefat" rows="3"><?php echo $instance['content']; ?></textarea>
  41. </label>
  42. </p>
  43. <p>
  44. <label>
  45. 标签:
  46. <input id="<?php echo $this->get_field_id('tag'); ?>" name="<?php echo $this->get_field_name('tag'); ?>" type="text" value="<?php echo $instance['tag']; ?>" class="widefat" />
  47. </label>
  48. </p>
  49. <p>
  50. <label>
  51. 链接:
  52. <input style="width:100%;" id="<?php echo $this->get_field_id('link'); ?>" name="<?php echo $this->get_field_name('link'); ?>" type="url" value="<?php echo $instance['link']; ?>" size="24" />
  53. </label>
  54. </p>
  55. <p>
  56. <label>
  57. 样式:
  58. <select style="width:100%;" id="<?php echo $this->get_field_id('style'); ?>" name="<?php echo $this->get_field_name('style'); ?>" style="width:100%;">
  59. <option value="style01" <?php selected('style01', $instance['style']); ?>>蓝色</option>
  60. <option value="style02" <?php selected('style02', $instance['style']); ?>>橘红色</option>
  61. <option value="style03" <?php selected('style03', $instance['style']); ?>>绿色</option>
  62. <option value="style04" <?php selected('style04', $instance['style']); ?>>紫色</option>
  63. <option value="style05" <?php selected('style05', $instance['style']); ?>>青色</option>
  64. </select>
  65. </label>
  66. </p>
  67. <p>
  68. <label>
  69. <input style="vertical-align:-3px;margin-right:4px;" class="checkbox" type="checkbox" <?php checked( $instance['blank'], 'on' ); ?> id="<?php echo $this->get_field_id('blank'); ?>" name="<?php echo $this->get_field_name('blank'); ?>">新打开浏览器窗口
  70. </label>
  71. </p>
  72. <?php
  73. }
  74. }
  75. ?>