Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Register Resent News widget
- *
- */
- add_action('widgets_init','wbr_resent_news_widget');
- function wbr_resent_news_widget(){
- return register_widget('wbr_resent_news_widget');
- }
- class wbr_resent_news_widget extends WP_Widget{
- function __construct() {
- parent::__construct(
- 'wbr_resent_news_widget', // Base ID
- __('WBR : HC Recent News Widget', 'health'), // Name
- array( 'description' => __( 'Recent News widget ', 'health' ), ) // Args
- );
- }
- public function widget( $args , $instance ) {
- $instance['title'] = isset($instance['title']) ? $instance['title'] : '';
- $instance['show_news'] = isset($instance['show_news']) ? $instance['show_news'] : 3;
- $current_options = wp_parse_args( get_option('hc_pro_options', array() ), theme_data_setup());
- $loop = array();
- $loop['post_type'] = 'post';
- $loop['showposts'] = $instance['show_news'];
- $loop['ignore_sticky_posts'] = 1;
- if( $current_options['home_slider_post_enable'] == false )
- {
- $loop['category__not_in'] = $current_options['slider_category'];
- }
- if( $current_options['home_testimonial_post_enable'] == false )
- {
- $loop['tax_query'] = array(
- array(
- 'taxonomy' => 'post_format',
- 'field' => 'slug',
- 'terms' => array('post-format-quote'),
- 'operator' => 'NOT IN'
- )
- );
- }
- $news_query = new WP_Query($loop);
- echo $args['before_widget'];
- if($instance['title']):
- echo $args['before_title'] . $instance['title'] . $args['after_title'];
- endif;
- if( $news_query->have_posts() ) :
- while ( $news_query->have_posts() ) : $news_query->the_post();
- ?>
- <div class="media hc_post_area">
- <aside class="hc_post-date-type">
- <div class="date entry-date updated">
- <?php
- $defalt_arg =array('class' => "img-responsive home_recent_img");
- if(has_post_thumbnail()):
- the_post_thumbnail('', $defalt_arg);
- endif;
- ?>
- </div>
- </aside>
- <div class="media-body">
- <h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>
- <p><?php echo custom_excerpt(30,'...'); ?></p>
- </div>
- </div>
- <?php
- endwhile;
- endif;
- echo $args['after_widget'];
- }
- public function form( $instance ) {
- $instance['title'] = isset($instance['title']) ? $instance['title'] : '';
- $instance['show_news'] = isset($instance['show_news']) ? $instance['show_news'] : 3;
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:','health' ); ?></label>
- <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']; ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'show_news' ); ?>"><?php _e( 'Number of news to show :','health' ); ?></label>
- <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']; ?>" />
- </p>
- <?php
- }
- public function update( $new_instance, $old_instance ) {
- $instance = array();
- $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? $new_instance['title'] : '';
- $instance['show_news'] = ( ! empty( $new_instance['show_news'] ) ) ? $new_instance['show_news'] : '';
- return $instance;
- }
- }
Add Comment
Please, Sign In to add comment