Advertisement
rhandom

Accompany Text Widget Clean

Feb 16th, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.42 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Accompany Text Widget
  4. Plugin URI: http://egetway.com/
  5. Description: Accompany Post Widget grabs a Accompany post and the associated thumbnail to display on your sidebar
  6. Author: Egetway
  7. Version: 1
  8. Author URI: http://egetway.com/
  9. */
  10.  
  11.  
  12. class AccompanyPostWidget extends WP_Widget
  13. {
  14.    
  15.    
  16.    
  17.   function AccompanyPostWidget()
  18.   {
  19.     $widget_ops = array('classname' => 'AccompanyPostWidget', 'description' => 'Displays a Accompany post with thumbnail' );
  20.     $this->WP_Widget('AccompanyPostWidget', 'Accompany Text Widget', $widget_ops);
  21.     $plugin_dir = basename(dirname(__FILE__));
  22.     load_plugin_textdomain( 'accompany-text', false, $plugin_dir );
  23.   }
  24.  
  25.   function form($instance)
  26.   {
  27.     $instance = wp_parse_args( (array) $instance, array( 'number' => '','text' => '', 'imagesPath' => '','cssClass' => '') );
  28.     $title = $instance['number'];
  29.     $text = $instance['text'];
  30.     $imagesPath= $instance['imagesPath'];
  31.     $cssClass= $instance['cssClass'];
  32. ?>
  33.   <p><label for="<?php echo $this->get_field_id('number'); ?>">Number : <input class="widefat" id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo attribute_escape($number); ?>" /></label></p>
  34.    <p><label for="<?php echo $this->get_field_id('text'); ?>">Text :
  35.    <textarea class="widefat" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo attribute_escape($text); ?></textarea>
  36.    </label></p>
  37.    <p><label for="<?php echo $this->get_field_id('imagesPath'); ?>">images path : <input class="widefat" id="<?php echo $this->get_field_id('imagesPath'); ?>" name="<?php echo $this->get_field_name('imagesPath'); ?>" type="text" value="<?php echo attribute_escape($imagesPath); ?>" /></label></p>
  38.    
  39.       <p><label for="<?php echo $this->get_field_id('cssClass'); ?>">Css Class : <input class="widefat" id="<?php echo $this->get_field_id('cssClass'); ?>" name="<?php echo $this->get_field_name('cssClass'); ?>" type="text" value="<?php echo attribute_escape($cssClass); ?>" /></label></p>
  40.    
  41. <?php
  42.   }
  43.  
  44.   function update($new_instance, $old_instance)
  45.   {
  46.     $instance = $old_instance;
  47.     $instance['number'] = $new_instance['number'];
  48.     $instance['text'] = $new_instance['text'];
  49.     $instance['imagesPath'] = $new_instance['imagesPath'];
  50.     $instance['cssClass'] = $new_instance['cssClass'];
  51.      
  52.     return $instance;
  53.   }
  54.  
  55.   function widget($args, $instance)
  56.   {
  57.     extract($args, EXTR_SKIP);
  58.  
  59.     echo $before_widget;
  60.     $number = empty($instance['number']) ? ' ' : apply_filters('widget_number', $instance['number']);
  61.     $text = empty($instance['text']) ? ' ' : apply_filters('widget_text', $instance['text']);
  62.     $imagesPath = empty($instance['imagesPath']) ? ' ' : apply_filters('widget_imagesPath', $instance['imagesPath']);
  63.     $cssClass = empty($instance['cssClass']) ? ' ' : apply_filters('widget_cssClass', $instance['cssClass']);
  64.    
  65.    
  66.    
  67.     // WIDGET CODE GOES HERE
  68.     echo '<div class="box '.$cssClass.'">
  69.  <div class="round">
  70.     <div class="con">';
  71.          if (!empty($number)){ echo ' <span class="num">'.$number.'</span>';}
  72.         echo $text;
  73.     if (!empty($imagesPath)){ echo '<div class="iconBox"><img src="'.$imagesPath.'" class="icon" /> </div>';}
  74.     echo ' </div>
  75.  </div>
  76. </div>';
  77.  
  78.     echo $after_widget;
  79.   }
  80.  
  81.  
  82.  
  83. }
  84.  
  85. add_action( 'widgets_init', create_function('', 'return register_widget("AccompanyPostWidget");') );?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement