mh_custom_pages_widget

The MH Corporate basic mh custom pages widget class.

Defined (1)

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

/includes/widgets/mh-custom-pages.php  
  1. class mh_custom_pages_widget extends WP_Widget { 
  2. function __construct() { 
  3. parent::__construct( 
  4. 'mh_custom_pages', esc_html_x('MH Custom Pages (lite)', 'widget name', 'mh-corporate-basic'),  
  5. array( 
  6. 'classname' => 'mh_custom_pages',  
  7. 'description' => esc_html__('Custom Pages Widget to display pages based on page IDs.', 'mh-corporate-basic'),  
  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. $pages = empty($instance['pages']) ? '' : $instance['pages']; 
  14.  
  15. echo $before_widget; 
  16. if (!empty( $title)) { echo $before_title . $title . $after_title;} ?> 
  17. <ul class="cp-widget clearfix"> <?php 
  18. $include_ids = explode(', ', $pages); 
  19. $args = array('post_type' => 'page', 'post__in' => $include_ids, 'orderby' => 'post__in'); 
  20. $widget_loop = new WP_Query($args); 
  21. while ($widget_loop->have_posts()) : $widget_loop->the_post(); ?> 
  22. <li class="cp-wrap clearfix"> 
  23. <div class="cp-thumb-xl"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php if (has_post_thumbnail()) { the_post_thumbnail('cp_large'); } else { echo '<img src="' . get_template_directory_uri() . '/images/noimage_cp_large.png' . '" alt="No Picture" />'; } ?></a></div> 
  24. <div class="cp-data"> 
  25. <h3 class="cp-xl-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3> 
  26. </div> 
  27. <?php mh_excerpt(); ?> 
  28. </li><?php 
  29. endwhile; 
  30. wp_reset_postdata(); ?> 
  31. </ul><?php 
  32. echo $after_widget; 
  33. function update($new_instance, $old_instance) { 
  34. $instance = $old_instance; 
  35. $instance['title'] = sanitize_text_field($new_instance['title']); 
  36. $instance['pages'] = sanitize_text_field($new_instance['pages']); 
  37.  
  38. return $instance; 
  39. function form($instance) { 
  40. $defaults = array('title' => '', 'pages' => ''); 
  41. $instance = wp_parse_args((array) $instance, $defaults); ?> 
  42.  
  43. <p> 
  44. <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title (optional):', 'mh-corporate-basic'); ?></label> 
  45. <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'); ?>" /> 
  46. </p> 
  47. <p> 
  48. <label for="<?php echo $this->get_field_id('pages'); ?>"><?php _e('Page ID:', 'mh-corporate-basic'); ?></label> 
  49. <input class="widefat" type="text" value="<?php echo esc_attr($instance['pages']); ?>" name="<?php echo $this->get_field_name('pages'); ?>" id="<?php echo $this->get_field_id('pages'); ?>" /> 
  50. </p> 
  51. <p> 
  52. <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'); ?> 
  53. </p><?php