mh_slider_hp_widget

The MH Corporate basic mh slider hp widget class.

Defined (1)

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

/includes/widgets/mh-slider.php  
  1. class mh_slider_hp_widget extends WP_Widget { 
  2. function __construct() { 
  3. parent::__construct( 
  4. 'mh_slider_hp', esc_html_x('MH Slider (lite)', 'widget name', 'mh-corporate-basic'),  
  5. array( 
  6. 'classname' => 'mh_slider_hp',  
  7. 'description' => esc_html__('Slider widget for use on homepage template.', 'mh-corporate-basic') 
  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'] : 1; 
  15.  
  16. echo $before_widget; ?> 
  17. <section id="mh-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/noimage_940x400.png' . '" alt="No Picture" />'; } ?> 
  26. </a> 
  27. <div class="slide-caption"> 
  28. <div class="slide-data"> 
  29. <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><h2 class="slide-title"><?php the_title(); ?></h2></a> 
  30. <div class="slide-excerpt"><?php mh_excerpt(); ?></div> 
  31. </div> 
  32. </div> 
  33. </article> 
  34. </li><?php 
  35. endwhile; wp_reset_postdata(); ?> 
  36. </ul> 
  37. </section><?php 
  38. echo $after_widget; 
  39. function update($new_instance, $old_instance) { 
  40. $instance = $old_instance; 
  41. $instance['category'] = absint($new_instance['category']); 
  42. $instance['postcount'] = absint($new_instance['postcount']); 
  43. $instance['offset'] = absint($new_instance['offset']); 
  44. $instance['sticky'] = isset($new_instance['sticky']) ? strip_tags($new_instance['sticky']) : ''; 
  45. return $instance; 
  46. function form($instance) { 
  47. $defaults = array('category' => '', 'tags' => '', 'postcount' => '5', 'offset' => '0', 'sticky' => 1); 
  48. $instance = wp_parse_args((array) $instance, $defaults); ?> 
  49.  
  50. <p> 
  51. <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e('Select a Category:', 'mh-corporate-basic'); ?></label> 
  52. <select id="<?php echo $this->get_field_id('category'); ?>" class="widefat" name="<?php echo $this->get_field_name('category'); ?>"> 
  53. <option value="0" <?php if (!$instance['category']) echo 'selected="selected"'; ?>><?php _e('All', 'mh-corporate-basic'); ?></option> 
  54. <?php 
  55. $categories = get_categories(array('type' => 'post')); 
  56. foreach($categories as $cat) { 
  57. echo '<option value="' . $cat->cat_ID . '"'; 
  58. if ($cat->cat_ID == $instance['category']) { echo ' selected="selected"'; } 
  59. echo '>' . $cat->cat_name . ' (' . $cat->category_count . ')'; 
  60. echo '</option>'; 
  61. ?> 
  62. </select> 
  63. </p> 
  64. <p> 
  65. <label for="<?php echo $this->get_field_id('postcount'); ?>"><?php _e('Limit Post Number:', 'mh-corporate-basic'); ?></label> 
  66. <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'); ?>" /> 
  67. </p> 
  68. <p> 
  69. <label for="<?php echo $this->get_field_id('offset'); ?>"><?php _e('Skip Posts (Offset):', 'mh-corporate-basic'); ?></label> 
  70. <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'); ?>" /> 
  71. </p> 
  72. <p> 
  73. <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']); ?>/> 
  74. <label for="<?php echo $this->get_field_id('sticky'); ?>"><?php _e('Ignore Sticky Posts', 'mh-corporate-basic'); ?></label> 
  75. </p> 
  76. <p> 
  77. <strong>Info:</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-corporate-basic'); ?> 
  78. </p><?php