mh_impact_lite_slider_widget

The MH Impact lite mh impact lite slider widget class.

Defined (1)

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

/includes/widgets/mh-slider.php  
  1. class mh_impact_lite_slider_widget extends WP_Widget { 
  2. function __construct() { 
  3. parent::__construct( 
  4. 'mh_impact_lite_slider_widget', esc_html_x('MH Slider (Homepage)', 'widget name', 'mh-impact-lite'),  
  5. array( 
  6. 'classname' => 'mh_impact_lite_slider_widget',  
  7. 'description' => esc_html__('Slider widget for use on homepage template.', 'mh-impact-lite') 
  8. ); 
  9. function widget($args, $instance) { 
  10. extract($args); 
  11. $category = isset($instance['category']) ? $instance['category'] : ''; 
  12. $postcount = empty($instance['postcount']) ? '5' : $instance['postcount']; 
  13. $offset = empty($instance['offset']) ? '' : $instance['offset']; 
  14. $sticky = isset($instance['sticky']) ? $instance['sticky'] : 0; 
  15.  
  16. echo $before_widget; ?> 
  17. <section id="slider-<?php echo rand(1, 9999); ?>" class="flexslider"> 
  18. <ul class="slides"><?php 
  19. $args = array('posts_per_page' => $postcount, 'cat' => $category, 'offset' => $offset, 'ignore_sticky_posts' => $sticky); 
  20. $slider = new WP_query($args); 
  21. while ($slider->have_posts()) : $slider->the_post(); ?> 
  22. <li> 
  23. <article class="slide-wrap"> 
  24. <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> 
  25. <?php if (has_post_thumbnail()) { the_post_thumbnail('slider'); } else { echo '<img src="' . get_template_directory_uri() . '/images/placeholder-slider.jpg' . '" alt="No Picture" />'; } ?> 
  26. </a> 
  27. <header class="slide-caption"> 
  28. <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><h2 class="slide-title"><?php the_title(); ?></h2></a> 
  29. </header> 
  30. </article> 
  31. </li><?php 
  32. endwhile; wp_reset_postdata(); ?> 
  33. </ul> 
  34. </section><?php 
  35. echo $after_widget; 
  36. function update($new_instance, $old_instance) { 
  37. $instance = $old_instance; 
  38. $instance['category'] = absint($new_instance['category']); 
  39. $instance['postcount'] = absint($new_instance['postcount']); 
  40. $instance['offset'] = absint($new_instance['offset']); 
  41. $instance['sticky'] = strip_tags($new_instance['sticky']); 
  42. return $instance; 
  43. function form($instance) { 
  44. $defaults = array('category' => '', 'postcount' => '5', 'offset' => '0', 'sticky' => 0); 
  45. $instance = wp_parse_args((array) $instance, $defaults); ?> 
  46.  
  47. <p> 
  48. <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e('Select a Category:', 'mh-impact-lite'); ?></label> 
  49. <select id="<?php echo $this->get_field_id('category'); ?>" class="widefat" name="<?php echo $this->get_field_name('category'); ?>"> 
  50. <option value="0" <?php if (!$instance['category']) echo 'selected="selected"'; ?>><?php _e('All', 'mh-impact-lite'); ?></option> 
  51. <?php 
  52. $categories = get_categories(array('type' => 'post')); 
  53. foreach($categories as $cat) { 
  54. echo '<option value="' . $cat->cat_ID . '"'; 
  55. if ($cat->cat_ID == $instance['category']) { echo ' selected="selected"'; } 
  56. echo '>' . $cat->cat_name . ' (' . $cat->category_count . ')'; 
  57. echo '</option>'; 
  58. ?> 
  59. </select> 
  60. </p> 
  61. <p> 
  62. <label for="<?php echo $this->get_field_id('postcount'); ?>"><?php _e('Limit Post Number:', 'mh-impact-lite'); ?></label> 
  63. <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'); ?>" /> 
  64. </p> 
  65. <p> 
  66. <label for="<?php echo $this->get_field_id('offset'); ?>"><?php _e('Skip Posts (Offset):', 'mh-impact-lite'); ?></label> 
  67. <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'); ?>" /> 
  68. </p> 
  69. <p> 
  70. <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']); ?>/> 
  71. <label for="<?php echo $this->get_field_id('sticky'); ?>"><?php _e('Ignore Sticky Posts', 'mh-impact-lite'); ?></label> 
  72. </p> 
  73. <p> 
  74. <strong><?php _e('Info:', 'mh-impact-lite'); ?></strong> <?php _e('This is the lite version of this widget with basic features. If you need more professional features and options, you can upgrade to the premium version of this theme.', 'mh-impact-lite'); ?> 
  75. </p><?php