mh_magazine_lite_posts_large

The MH Magazine lite mh magazine lite posts large class.

Defined (1)

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

/includes/widgets/mh-posts-large.php  
  1. class mh_magazine_lite_posts_large extends WP_Widget { 
  2. function __construct() { 
  3. parent::__construct( 
  4. 'mh_magazine_lite_posts_large', esc_html_x('MH Posts Large [lite]', 'widget name', 'mh-magazine-lite'),  
  5. array( 
  6. 'classname' => 'mh_magazine_lite_posts_large',  
  7. 'description' => esc_html__('MH Posts Large widget to display posts (large-sized) including thumbnail images.', 'mh-magazine-lite'),  
  8. 'customize_selective_refresh' => true 
  9. ); 
  10. function widget($args, $instance) { 
  11. $defaults = array('title' => '', 'category' => 0, 'tags' => '', 'postcount' => 1, 'offset' => 0, 'sticky' => 1); 
  12. $instance = wp_parse_args($instance, $defaults); 
  13. $query_args = array(); 
  14. $query_args['ignore_sticky_posts'] = $instance['sticky']; 
  15. if (0 !== $instance['category']) { 
  16. $query_args['cat'] = $instance['category']; 
  17. if (!empty($instance['tags'])) { 
  18. $tag_slugs = explode(', ', $instance['tags']); 
  19. $tag_slugs = array_map('trim', $tag_slugs); 
  20. $query_args['tag_slug__in'] = $tag_slugs; 
  21. if (!empty($instance['postcount'])) { 
  22. $query_args['posts_per_page'] = $instance['postcount']; 
  23. if (0 !== $instance['offset']) { 
  24. $query_args['offset'] = $instance['offset']; 
  25. $widget_posts = new WP_Query($query_args); 
  26. echo $args['before_widget']; 
  27. if ($widget_posts->have_posts()) : 
  28. if (!empty($instance['title'])) { 
  29. echo $args['before_title'] . esc_html(apply_filters('widget_title', $instance['title'])) . $args['after_title']; 
  30. echo '<div class="mh-posts-large-widget">' . "\n"; 
  31. while ($widget_posts->have_posts()) : $widget_posts->the_post(); 
  32. get_template_part('content', 'large'); 
  33. endwhile; 
  34. wp_reset_postdata(); 
  35. echo '</div>' . "\n"; 
  36. endif; 
  37. echo $args['after_widget']; 
  38. function update($new_instance, $old_instance) { 
  39. $instance = array(); 
  40. if (!empty($new_instance['title'])) { 
  41. $instance['title'] = sanitize_text_field($new_instance['title']); 
  42. if (0 !== absint($new_instance['category'])) { 
  43. $instance['category'] = absint($new_instance['category']); 
  44. if (!empty($new_instance['tags'])) { 
  45. $tag_slugs = explode(', ', $new_instance['tags']); 
  46. $tag_slugs = array_map('sanitize_title', $tag_slugs); 
  47. $instance['tags'] = implode(', ', $tag_slugs); 
  48. if (0 !== absint($new_instance['postcount'])) { 
  49. if (absint($new_instance['postcount']) > 50) { 
  50. $instance['postcount'] = 50; 
  51. } else { 
  52. $instance['postcount'] = absint($new_instance['postcount']); 
  53. if (0 !== absint($new_instance['offset'])) { 
  54. if (absint($new_instance['offset']) > 50) { 
  55. $instance['offset'] = 50; 
  56. } else { 
  57. $instance['offset'] = absint($new_instance['offset']); 
  58. return $instance; 
  59. function form($instance) { 
  60. $defaults = array('title' => '', 'category' => 0, 'tags' => '', 'postcount' => 1, 'offset' => 0, 'sticky' => 1); 
  61. $instance = wp_parse_args($instance, $defaults); ?> 
  62. <p> 
  63. <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title:', 'mh-magazine-lite'); ?></label> 
  64. <input class="widefat" type="text" value="<?php echo esc_attr($instance['title']); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" id="<?php echo esc_attr($this->get_field_id('title')); ?>" /> 
  65. </p> 
  66. <p> 
  67. <label for="<?php echo esc_attr($this->get_field_id('category')); ?>"><?php esc_html_e('Select a Category:', 'mh-magazine-lite'); ?></label> 
  68. <select id="<?php echo esc_attr($this->get_field_id('category')); ?>" class="widefat" name="<?php echo esc_attr($this->get_field_name('category')); ?>"> 
  69. <option value="0" <?php selected(0, $instance['category']); ?>><?php esc_html_e('All', 'mh-magazine-lite'); ?></option><?php 
  70. $categories = get_categories(); 
  71. foreach ($categories as $cat) { ?> 
  72. <option value="<?php echo absint($cat->cat_ID); ?>" <?php selected($cat->cat_ID, $instance['category']); ?>><?php echo esc_html($cat->cat_name) . ' (' . absint($cat->category_count) . ')'; ?></option><?php 
  73. } ?> 
  74. </select> 
  75. <small><?php _e('Select a category to display posts from.', 'mh-magazine-lite'); ?></small> 
  76. </p> 
  77. <p> 
  78. <label for="<?php echo esc_attr($this->get_field_id('tags')); ?>"><?php esc_html_e('Filter Posts by Tags (e.g. lifestyle):', 'mh-magazine-lite'); ?></label> 
  79. <input class="widefat" type="text" value="<?php echo esc_attr($instance['tags']); ?>" name="<?php echo esc_attr($this->get_field_name('tags')); ?>" id="<?php echo esc_attr($this->get_field_id('tags')); ?>" /> 
  80. </p> 
  81. <p> 
  82. <label for="<?php echo esc_attr($this->get_field_id('postcount')); ?>"><?php esc_html_e('Post Count (max. 50):', 'mh-magazine-lite'); ?></label> 
  83. <input class="widefat" type="text" value="<?php echo absint($instance['postcount']); ?>" name="<?php echo esc_attr($this->get_field_name('postcount')); ?>" id="<?php echo esc_attr($this->get_field_id('postcount')); ?>" /> 
  84. </p> 
  85. <p> 
  86. <label for="<?php echo esc_attr($this->get_field_id('offset')); ?>"><?php esc_html_e('Skip Posts (max. 50):', 'mh-magazine-lite'); ?></label> 
  87. <input class="widefat" type="text" value="<?php echo absint($instance['offset']); ?>" name="<?php echo esc_attr($this->get_field_name('offset')); ?>" id="<?php echo esc_attr($this->get_field_id('offset')); ?>" /> 
  88. </p> 
  89. <p> 
  90. <strong><?php esc_html_e('Info:', 'mh-magazine-lite'); ?></strong> <?php esc_html_e('This is the lite version of this widget with basic features. More features and options are available in the premium version of MH Magazine.', 'mh-magazine-lite'); ?> 
  91. </p><?php