mh_impact_lite_recent_posts

The MH Impact lite mh impact lite recent posts class.

Defined (1)

The class is defined in the following location(s).

/includes/widgets/mh-recent-posts.php  
  1. class mh_impact_lite_recent_posts extends WP_Widget { 
  2. function __construct() { 
  3. parent::__construct( 
  4. 'mh_impact_lite_recent_posts', esc_html_x('MH Recent Posts', 'widget name', 'mh-impact-lite'),  
  5. array( 
  6. 'classname' => 'mh_impact_lite_recent_posts',  
  7. 'description' => esc_html__('Display a list of most recent posts.', 'mh-impact-lite'),  
  8. 'customize_selective_refresh' => true 
  9. ); 
  10. function widget($args, $instance) { 
  11. extract($args); 
  12. $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); 
  13. $postcount = empty($instance['postcount']) ? '5' : $instance['postcount']; 
  14. $offset = empty($instance['offset']) ? '' : $instance['offset']; 
  15. $sticky = isset($instance['sticky']) ? $instance['sticky'] : 0; 
  16.  
  17. echo $before_widget; 
  18. if (!empty($title)) { echo $before_title . esc_attr($title) . $after_title; } 
  19. $args = array('posts_per_page' => $postcount, 'offset' => $offset, 'ignore_sticky_posts' => $sticky); 
  20. $widget_loop = new WP_Query($args); ?> 
  21. <ul class="mh-rp-widget widget-list"><?php 
  22. while ($widget_loop->have_posts()) : $widget_loop->the_post(); ?> 
  23. <li class="rp-widget-item"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php the_title(); ?></a></li><?php 
  24. endwhile; 
  25. wp_reset_postdata(); ?> 
  26. </ul><?php 
  27. echo $after_widget; 
  28. function update($new_instance, $old_instance) { 
  29. $instance = $old_instance; 
  30. $instance['title'] = sanitize_text_field($new_instance['title']); 
  31. $instance['postcount'] = absint($new_instance['postcount']); 
  32. $instance['offset'] = absint($new_instance['offset']); 
  33. $instance['sticky'] = isset($new_instance['sticky']) ? strip_tags($new_instance['sticky']) : ''; 
  34. return $instance; 
  35. function form($instance) { 
  36. $defaults = array('title' => '', 'postcount' => '5', 'offset' => '0', 'sticky' => 0); 
  37. $instance = wp_parse_args((array) $instance, $defaults); ?> 
  38.  
  39. <p> 
  40. <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'mh-impact-lite'); ?></label> 
  41. <input class="widefat" type="text" value="<?php echo esc_attr($instance['title']); ?>" name="<?php echo $this->get_field_name('title'); ?>" id="<?php echo $this->get_field_id('title'); ?>" /> 
  42. </p> 
  43. <p> 
  44. <label for="<?php echo $this->get_field_id('postcount'); ?>"><?php _e('Limit Post Number:', 'mh-impact-lite'); ?></label> 
  45. <input class="widefat" type="text" value="<?php echo esc_attr($instance['postcount']); ?>" name="<?php echo $this->get_field_name('postcount'); ?>" id="<?php echo $this->get_field_id('postcount'); ?>" /> 
  46. </p> 
  47. <p> 
  48. <label for="<?php echo $this->get_field_id('offset'); ?>"><?php _e('Skip Posts (Offset):', 'mh-impact-lite'); ?></label> 
  49. <input class="widefat" type="text" value="<?php echo esc_attr($instance['offset']); ?>" name="<?php echo $this->get_field_name('offset'); ?>" id="<?php echo $this->get_field_id('offset'); ?>" /> 
  50. </p> 
  51. <p> 
  52. <input id="<?php echo $this->get_field_id('sticky'); ?>" name="<?php echo $this->get_field_name('sticky'); ?>" type="checkbox" value="1" <?php checked('1', $instance['sticky']); ?>/> 
  53. <label for="<?php echo $this->get_field_id('sticky'); ?>"><?php _e('Ignore Sticky Posts', 'mh-impact-lite'); ?></label> 
  54. </p><?php