Advertisement
Guest User

Untitled

a guest
Aug 26th, 2011
871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.51 KB | None | 0 0
  1. <?php
  2.  
  3. class Hbbot_Testimonials_Widget extends WP_Widget {
  4.    
  5.     function __construct() {
  6.        
  7.         $widget_ops = array(
  8.             'classname' => 'hbbot_testimonial_widget',
  9.             'description' => 'Display groups of testimonials in your sidebar or other widgetized areas'
  10.         );
  11.        
  12.         parent::__construct( 'hbbot_testy_widget', 'HBBOT Testimonials Wiget', $widget_ops );
  13.        
  14.     }
  15.    
  16.     function form( $instance ) {
  17.         $title = esc_attr( $instance[ 'title' ] );
  18.         $num_posts = esc_attr( $instance[ 'num_posts' ] );
  19.         $use_thumb = esc_attr( $instance[ 'use_thumb' ] );
  20.         if( isset( $instance['use_groups'] ) ) {
  21.             $use_groups = $instance[ 'use_groups' ];
  22.         } else {
  23.             $use_groups = array('all');
  24.         }
  25.        
  26.         $groups = get_terms('hbbot_group', array('hide_empty' => false));
  27.         $tcount = wp_count_posts( 'hbbot_testimonial' );
  28.         $gcount = wp_count_terms( 'hbbot_group', array( 'hide_empty' => false ) );
  29.         if( $tcount > 0 ):
  30.         ?>
  31.        
  32.             <p>
  33.               <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title: (optional)
  34.                 <input class="widefat"
  35.                   id="<?php echo $this->get_field_id( 'title' ); ?>"
  36.                   name="<?php echo $this->get_field_name( 'title' ); ?>"
  37.                   type="text"
  38.                   value="<?php echo attribute_escape( $title ); ?>"  />
  39.               </label>
  40.             </p>
  41.             <p>
  42.               <label for="<?php echo $this->get_field_id( 'num_posts' ); ?>">Testimonials to display:
  43.                 <input size="3"
  44.                   id="<?php echo $this->get_field_id( 'num_posts' ); ?>"
  45.                   name="<?php echo $this->get_field_name( 'num_posts' ); ?>"
  46.                   type="text"
  47.                   value="<?php echo attribute_escape( $num_posts ); ?>"  />
  48.               </label>
  49.             </p>
  50.             <?php if( $gcount > 0 ) : ?>
  51.                 <p>Limit to these Groups:<br />
  52.                 <select
  53.                   class="widefat"
  54.                   size="5"
  55.                   style="height: auto;"
  56.                   id="<?php echo $this->get_field_id( 'use_groups' );?>"
  57.                   name="<?php echo $this->get_field_name( 'use_groups' );?>"
  58.                   multiple="multiple">
  59.                     <option value="all"<?php if( in_array( 'all', $use_groups ) !== FALSE ): ?> selected="selected"<?php endif;?> >All Groups</option>
  60.                   <?php foreach( $groups as $g ): ?>
  61.                     <option value="<?php echo $g->term_id; ?>" <?php if( in_array( $g->term_id, $use_groups ) !== FALSE ) { ?>selected="selected"<?php } ?> ><?php echo $g->name . " (". $g->count . ")"; ?></option>
  62.                   <?php endforeach; ?>
  63.                   </select>
  64.                 </p>
  65.             <?php else: ?>
  66.                 <p>You haven't defined any Groups for your Testimonials. Once you <a href="<?php get_bloginfo('url'); ?>/wp-admin/edit-tags.php?taxonomy=hbbot_group&post_type=hbbot_testimonial">create some</a> you can use this widget to display specific groups of testimonials.</p>
  67.             <?php endif; ?>
  68.             <p>
  69.               <label for="<?php echo $this->get_field_id( 'use_thumb' ); ?>">
  70.                 <input size="3"
  71.                   id="<?php echo $this->get_field_id( 'use_thumb' ); ?>"
  72.                   name="<?php echo $this->get_field_name( 'use_thumb' ); ?>"
  73.                   type="checkbox"
  74.                   <?php echo ( $use_thumb ) ? 'checked="checked"' : ''; ?> /> Show Thumbnails?
  75.               </label>
  76.             </p>
  77.         <?php
  78.         else :
  79.         ?>
  80.             <p>Oops! You haven't created any Testimonials, yet. <a href="<?php get_bloginfo('url'); ?>/wp-admin/post-new.php?post_type=hbbot_testimonial">Create some now.</a></p>
  81.         <?php
  82.         endif;
  83.     }
  84.    
  85.     function update( $new_instance, $old_instance ) {
  86.         $instance = $old_instance;
  87.        
  88.         $instance['title'] = strip_tags( $new_instance[ 'title' ] );
  89.         $instance['num_posts'] = strip_tags( $new_instance[ 'num_posts' ] );
  90.         $instance['use_thumb'] = ( isset( $new_instance[ 'use_thumb' ] ) ) ? true : false;
  91.         $instance['use_groups'] = $new_instance[ 'use_groups' ] ;
  92.        
  93.         return $instance;
  94.        
  95.     }
  96.    
  97.     function widget( $args, $instance ) {
  98.        
  99.         extract( $args, EXTR_SKIP );
  100.        
  101.        
  102.         echo $before_widget;
  103.        
  104.         $title = apply_filters( 'widget_title', $instance[ 'title' ] );
  105.         $tlimit = (int)$instance[ 'num_posts' ];
  106.         $use_thumb = (bool)$instance[ 'use_thumb' ];
  107.  
  108.        
  109.     }
  110.    
  111. } // end class
  112.  
  113. add_action( 'widgets_init', 'hbbot_register_widget' );
  114. function hbbot_register_widget() { return register_widget( 'Hbbot_Testimonials_Widget' ); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement