Guest User

Untitled

a guest
Aug 26th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 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 : 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. ?><div><?php
  63. while ( $news_query->have_posts() ) : $news_query->the_post();
  64. ?>
  65.  
  66. <div class="media hc_post_area">
  67. <aside class="hc_post-date-type">
  68. <div class="date entry-date updated">
  69. <div class="day"><?php echo get_the_date('j'); ?></div>
  70. <div class="month-year"><?php echo get_the_date('M , Y'); ?></div>
  71. </div>
  72. </aside>
  73. <div class="media-body">
  74. <h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>
  75. <p><?php echo custom_excerpt(30,'...'); ?></p>
  76. </div>
  77. </div>
  78.  
  79. <?php
  80. endwhile;
  81.  
  82. endif;
  83. ?></div><?php
  84. echo $args['after_widget'];
  85. }
  86.  
  87. public function form( $instance ) {
  88. $instance['title'] = isset($instance['title']) ? $instance['title'] : '';
  89. $instance['show_news'] = isset($instance['show_news']) ? $instance['show_news'] : 3;
  90. ?>
  91.  
  92. <p>
  93. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title','health' ); ?></label>
  94. <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']; ?>" />
  95. </p>
  96.  
  97. <p>
  98. <label for="<?php echo $this->get_field_id( 'show_news' ); ?>"><?php _e('Number of news to show','health' ); ?></label>
  99. <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']; ?>" />
  100. </p>
  101.  
  102. <?php
  103. }
  104.  
  105. public function update( $new_instance, $old_instance ) {
  106.  
  107. $instance = array();
  108. $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? $new_instance['title'] : '';
  109. $instance['show_news'] = ( ! empty( $new_instance['show_news'] ) ) ? $new_instance['show_news'] : '';
  110.  
  111. return $instance;
  112. }
  113. }
Add Comment
Please, Sign In to add comment