SHARE
TWEET

Untitled

a guest Oct 5th, 2016 24 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * Register Resent News widget
  4.  *
  5.  */
  6. add_action('widgets_init','wbr_resent_news_widget');
  7. function wbr_resent_news_widget(){
  8.    
  9.     return register_widget('wbr_resent_news_widget');
  10. }
  11.  
  12. class wbr_resent_news_widget extends WP_Widget{
  13.    
  14.     function __construct() {
  15.         parent::__construct(
  16.             'wbr_resent_news_widget', // Base ID
  17.             __('WBR : HC Recent News Widget', 'health'), // Name
  18.             array( 'description' => __( 'Recent News widget ', 'health' ), ) // Args
  19.         );
  20.     }
  21.    
  22.     public function widget( $args , $instance ) {
  23.         $instance['title'] = isset($instance['title']) ? $instance['title'] : '';
  24.         $instance['show_news'] = isset($instance['show_news']) ? $instance['show_news'] : 3;
  25.         $current_options = wp_parse_args( get_option('hc_pro_options', array() ), theme_data_setup());
  26.        
  27.        
  28.         $loop = array();
  29.        
  30.         $loop['post_type'] = 'post';
  31.        
  32.         $loop['showposts'] = $instance['show_news'];
  33.        
  34.         $loop['ignore_sticky_posts'] = 1;
  35.        
  36.         if( $current_options['home_slider_post_enable'] == false )
  37.         {
  38.             $loop['category__not_in'] = $current_options['slider_category'];
  39.         }
  40.        
  41.         if( $current_options['home_testimonial_post_enable'] == false )
  42.         {
  43.             $loop['tax_query'] = array(
  44.                     array(
  45.                         'taxonomy' => 'post_format',
  46.                         'field' => 'slug',
  47.                         'terms' => array('post-format-quote'),
  48.                         'operator' => 'NOT IN'
  49.                     )
  50.                 );
  51.         }
  52.        
  53.         $news_query = new WP_Query($loop);
  54.        
  55.         echo $args['before_widget'];
  56.            
  57.             if($instance['title']):
  58.                 echo $args['before_title'] . $instance['title'] . $args['after_title'];
  59.             endif;
  60.            
  61.         if( $news_query->have_posts() ) :
  62.            
  63.             while ( $news_query->have_posts() ) : $news_query->the_post();
  64.                 ?>
  65.                 <div class="media hc_post_area">           
  66.                 <aside class="hc_post-date-type">
  67.                     <div class="date entry-date updated">
  68.                         <div class="day"><?php echo get_the_date('j'); ?></div>
  69.                         <div class="month-year"><?php echo get_the_date('M , Y'); ?></div>
  70.                     </div>
  71.                 </aside>
  72.                 <div class="media-body">
  73.                     <h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>
  74.                     <p><?php echo custom_excerpt(30,'...'); ?></p>
  75.                     <?php
  76.                         $defalt_arg =array('class' => "img-responsive");
  77.                         if(has_post_thumbnail()):
  78.                         the_post_thumbnail('', $defalt_arg);
  79.                         endif;
  80.                         ?>
  81.                 </div>
  82.             </div>
  83.                 <?php
  84.             endwhile;
  85.            
  86.         endif;
  87.        
  88.         echo $args['after_widget'];
  89.     }
  90.    
  91.     public function form( $instance ) {
  92.         $instance['title'] = isset($instance['title']) ? $instance['title'] : '';
  93.         $instance['show_news'] = isset($instance['show_news']) ? $instance['show_news'] : 3;
  94.     ?>
  95.    
  96.     <p>
  97.         <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:','health' ); ?></label>
  98.         <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $instance['title']; ?>" />
  99.     </p>
  100.    
  101.     <p>
  102.         <label for="<?php echo $this->get_field_id( 'show_news' ); ?>"><?php _e( 'Number of news to show :','health' ); ?></label>
  103.         <input size="3" maxlength="2" id="<?php echo $this->get_field_id( 'show_news' ); ?>" name="<?php echo $this->get_field_name( 'show_news' ); ?>" type="number" value="<?php echo $instance['show_news']; ?>" />
  104.     </p>
  105.        
  106.     <?php
  107.     }
  108.    
  109.     public function update( $new_instance, $old_instance ) {
  110.        
  111.         $instance = array();
  112.         $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? $new_instance['title'] : '';
  113.         $instance['show_news'] = ( ! empty( $new_instance['show_news'] ) ) ? $new_instance['show_news'] : '';
  114.        
  115.         return $instance;
  116.     }
  117. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top