Guest User

Untitled

a guest
Jan 27th, 2018
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  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. <?php
  69. $defalt_arg =array('class' => "img-responsive home_recent_img");
  70. if(has_post_thumbnail()):
  71. the_post_thumbnail('', $defalt_arg);
  72. endif;
  73. ?>
  74. </div>
  75. </aside>
  76. <div class="media-body">
  77. <h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>
  78. <p><?php echo custom_excerpt(30,'...'); ?></p>
  79.  
  80. </div>
  81. </div>
  82. <?php
  83. endwhile;
  84.  
  85. endif;
  86.  
  87. echo $args['after_widget'];
  88. }
  89.  
  90. public function form( $instance ) {
  91. $instance['title'] = isset($instance['title']) ? $instance['title'] : '';
  92. $instance['show_news'] = isset($instance['show_news']) ? $instance['show_news'] : 3;
  93. ?>
  94.  
  95. <p>
  96. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:','health' ); ?></label>
  97. <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']; ?>" />
  98. </p>
  99.  
  100. <p>
  101. <label for="<?php echo $this->get_field_id( 'show_news' ); ?>"><?php _e( 'Number of news to show :','health' ); ?></label>
  102. <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']; ?>" />
  103. </p>
  104.  
  105. <?php
  106. }
  107.  
  108. public function update( $new_instance, $old_instance ) {
  109.  
  110. $instance = array();
  111. $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? $new_instance['title'] : '';
  112. $instance['show_news'] = ( ! empty( $new_instance['show_news'] ) ) ? $new_instance['show_news'] : '';
  113.  
  114. return $instance;
  115. }
  116. }
Add Comment
Please, Sign In to add comment