mh_slider_hp_widget

The MH Corporate lite 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 mh_slider_hp_widget() { 
  3. $widget_ops = array('classname' => 'mh_slider_hp', 'description' => __('Slider widget for use on homepage template.', 'mhc')); 
  4. $this->WP_Widget('mh_slider_hp', __('MH Slider Widget lite (Homepage)', 'mhc'), $widget_ops); 
  5. function widget($args, $instance) { 
  6. extract($args); 
  7. $category = isset($instance['category']) ? $instance['category'] : ''; 
  8. $postcount = empty($instance['postcount']) ? '5' : $instance['postcount']; 
  9. $offset = empty($instance['offset']) ? '' : $instance['offset']; 
  10. $sticky = isset($instance['sticky']) ? $instance['sticky'] : 0; 
  11.  
  12. echo $before_widget; ?> 
  13. <section id="slider-<?php echo rand(1, 9999); ?>" class="flexslider"> 
  14. <ul class="slides"><?php 
  15. $args = array('posts_per_page' => $postcount, 'cat' => $category, 'offset' => $offset, 'ignore_sticky_posts' => $sticky); 
  16. $slider = new WP_query($args); 
  17. while ($slider->have_posts()) : $slider->the_post(); ?> 
  18. <li> 
  19. <article class="slide-wrap"> 
  20. <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> 
  21. <?php if (has_post_thumbnail()) { the_post_thumbnail('slider'); } else { echo '<img src="' . get_template_directory_uri() . '/images/noimage_940x400.png' . '" alt="No Picture" />'; } ?> 
  22. </a> 
  23. <div class="slide-caption"> 
  24. <div class="slide-data"> 
  25. <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><h2 class="slide-title"><?php the_title(); ?></h2></a> 
  26. <div class="slide-excerpt"><?php mh_excerpt(); ?></div> 
  27. </div> 
  28. </div> 
  29. </article> 
  30. </li><?php 
  31. endwhile; wp_reset_postdata(); ?> 
  32. </ul> 
  33. </section><?php 
  34. echo $after_widget; 
  35. function update($new_instance, $old_instance) { 
  36. $instance = $old_instance; 
  37. $instance['category'] = strip_tags($new_instance['category']); 
  38. $instance['postcount'] = strip_tags($new_instance['postcount']); 
  39. $instance['offset'] = strip_tags($new_instance['offset']); 
  40. $instance['sticky'] = strip_tags($new_instance['sticky']); 
  41. return $instance; 
  42. function form($instance) { 
  43. $defaults = array('category' => '', 'tags' => '', 'postcount' => '5', 'offset' => '0', 'sticky' => 0); 
  44. $instance = wp_parse_args((array) $instance, $defaults); ?> 
  45.  
  46. <p> 
  47. <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e('Select a Category:', 'mhc'); ?></label> 
  48. <select id="<?php echo $this->get_field_id('category'); ?>" class="widefat" name="<?php echo $this->get_field_name('category'); ?>"> 
  49. <option value="0" <?php if (!$instance['category']) echo 'selected="selected"'; ?>><?php _e('All', 'mhc'); ?></option> 
  50. <?php 
  51. $categories = get_categories(array('type' => 'post')); 
  52. foreach($categories as $cat) { 
  53. echo '<option value="' . $cat->cat_ID . '"'; 
  54. if ($cat->cat_ID == $instance['category']) { echo ' selected="selected"'; } 
  55. echo '>' . $cat->cat_name . ' (' . $cat->category_count . ')'; 
  56. echo '</option>'; 
  57. ?> 
  58. </select> 
  59. </p> 
  60. <p> 
  61. <label for="<?php echo $this->get_field_id('postcount'); ?>"><?php _e('Limit Post Number:', 'mhc'); ?></label> 
  62. <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'); ?>" /> 
  63. </p> 
  64. <p> 
  65. <label for="<?php echo $this->get_field_id('offset'); ?>"><?php _e('Skip Posts (Offset):', 'mhc'); ?></label> 
  66. <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'); ?>" /> 
  67. </p> 
  68. <p> 
  69. <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']); ?>/> 
  70. <label for="<?php echo $this->get_field_id('sticky'); ?>"><?php _e('Ignore Sticky Posts', 'mhc'); ?></label> 
  71. </p> 
  72. <p> 
  73. <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.', 'mhp'); ?> 
  74. </p><?php