mh_newsdesk_lite_posts_large

The MH Newsdesk lite mh newsdesk lite posts large class.

Defined (1)

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

/includes/widgets/mh-posts-large.php  
  1. class mh_newsdesk_lite_posts_large extends WP_Widget { 
  2. function __construct() { 
  3. parent::__construct( 
  4. 'mh_newsdesk_lite_posts_large', esc_html_x('MH Posts Large [lite]', 'widget name', 'mh-newsdesk-lite'),  
  5. array( 
  6. 'classname' => 'mh_newsdesk_lite_posts_large',  
  7. 'description' => esc_html__('Display post with large image on front page for use in "Home 1" or "Home 4" widget areas.', 'mh-newsdesk-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. $category = isset($instance['category']) ? $instance['category'] : ''; 
  14. $offset = empty($instance['offset']) ? '' : $instance['offset']; 
  15. $sticky = isset($instance['sticky']) ? $instance['sticky'] : 1; 
  16.  
  17. if ($category) { 
  18. $cat_url = get_category_link($category); 
  19. $before_title = $before_title . '<a href="' . esc_url($cat_url) . '" class="widget-title-link">'; 
  20. $after_title = '</a>' . $after_title; 
  21.  
  22. echo $before_widget; 
  23. if (!empty($title)) { echo $before_title . esc_attr($title) . $after_title; } 
  24. $args = array('posts_per_page' => '1', 'offset' => $offset, 'cat' => $category, 'ignore_sticky_posts' => $sticky); 
  25. $widget_loop = new WP_Query($args); ?> 
  26. <div class="mh-fp-large-widget clearfix"><?php 
  27. while ($widget_loop->have_posts()) : $widget_loop->the_post(); 
  28. get_template_part('content', 'lead'); 
  29. echo '<hr class="mh-separator">' . "\n"; 
  30. endwhile; 
  31. wp_reset_postdata(); ?> 
  32. </div><?php 
  33. echo $after_widget; 
  34. function update($new_instance, $old_instance) { 
  35. $instance = $old_instance; 
  36. $instance['title'] = sanitize_text_field($new_instance['title']); 
  37. $instance['category'] = absint($new_instance['category']); 
  38. $instance['offset'] = absint($new_instance['offset']); 
  39. $instance['sticky'] = isset($new_instance['sticky']) ? strip_tags($new_instance['sticky']) : ''; 
  40. return $instance; 
  41. function form($instance) { 
  42. $defaults = array('title' => '', 'category' => '', 'offset' => '0', 'sticky' => 1); 
  43. $instance = wp_parse_args((array) $instance, $defaults); ?> 
  44.  
  45. <p> 
  46. <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'mh-newsdesk-lite'); ?></label> 
  47. <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'); ?>" /> 
  48. </p> 
  49. <p> 
  50. <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e('Select a Category:', 'mh-newsdesk-lite'); ?></label> 
  51. <select id="<?php echo $this->get_field_id('category'); ?>" class="widefat" name="<?php echo $this->get_field_name('category'); ?>"> 
  52. <option value="0" <?php if (!$instance['category']) echo 'selected="selected"'; ?>><?php _e('All', 'mh-newsdesk-lite'); ?></option> 
  53. <?php 
  54. $categories = get_categories(array('type' => 'post')); 
  55. foreach($categories as $cat) { 
  56. echo '<option value="' . $cat->cat_ID . '"'; 
  57. if ($cat->cat_ID == $instance['category']) { echo ' selected="selected"'; } 
  58. echo '>' . $cat->cat_name . ' (' . $cat->category_count . ')'; 
  59. echo '</option>'; 
  60. ?> 
  61. </select> 
  62. </p> 
  63. <p> 
  64. <label for="<?php echo $this->get_field_id('offset'); ?>"><?php _e('Skip Posts (Offset):', 'mh-newsdesk-lite'); ?></label> 
  65. <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'); ?>" /> 
  66. </p> 
  67. <p> 
  68. <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']); ?>/> 
  69. <label for="<?php echo $this->get_field_id('sticky'); ?>"><?php _e('Ignore Sticky Posts', 'mh-newsdesk-lite'); ?></label> 
  70. </p> 
  71. <p> 
  72. <strong><?php _e('Info:', 'mh-newsdesk-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-newsdesk-lite'); ?> 
  73. </p><?php