widget_cssclass = 'bloglex-recent-widget'; $this->widget_description = __("Displays recent posts with an image", 'bloglex'); $this->widget_id = 'bloglex_recent_posts'; $this->widget_name = __('Bloglex: Recent Posts', 'bloglex'); $this->settings = $this->get_widget_settings(); parent::__construct(); } /** * Define widget settings. */ protected function get_widget_settings() { return array( 'title' => array( 'type' => 'text', 'label' => __('Title', 'bloglex'), 'std' => __('Recent Posts', 'bloglex'), ), 'style' => array( 'type' => 'select', 'label' => __('Display Style', 'bloglex'), 'options' => array( 'wpi-post-regular' => __('Regular View', 'bloglex'), 'wpi-post-list' => __('List View', 'bloglex'), 'wpi-post-card' => __('Card View', 'bloglex'), ), 'std' => 'wpi-post-list', ), 'font_size' => array( 'type' => 'select', 'label' => __('Entry title font size', 'bloglex'), 'options' => array( 'entry-title-xsmall' => __('Extra Small', 'bloglex'), 'entry-title-small' => __('Small', 'bloglex'), 'entry-title-medium' => __('Medium', 'bloglex'), 'entry-title-big' => __('Big', 'bloglex'), ), 'std' => 'entry-title-small', ), 'font_style' => array( 'type' => 'select', 'label' => __('Entry title font style', 'bloglex'), 'options' => array( 'entry-title-normal' => __('Normal', 'bloglex'), 'entry-title-italic' => __('Italic', 'bloglex'), ), 'std' => 'entry-title-normal', ), 'category' => array( 'type' => 'dropdown-taxonomies', 'label' => __('Select Category', 'bloglex'), 'args' => array( 'taxonomy' => 'category', 'class' => 'widefat', 'hierarchical' => true, 'show_count' => 1, 'show_option_all' => __('— Select —', 'bloglex'), ), ), 'number' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'std' => 5, 'label' => __('Number of posts to show', 'bloglex'), ), 'offset' => array( 'type' => 'number', 'step' => 1, 'min' => 0, 'max' => '', 'std' => '', 'label' => __( 'Offset', 'bloglex' ), 'desc' => __( 'Offsets are used to skip a certain number of WordPress posts before starting output. Set it to 0 if you do not wish to use this feature.', 'bloglex' ), ), 'orderby' => array( 'type' => 'select', 'std' => 'date', 'label' => __('Order by', 'bloglex'), 'options' => array( 'date' => __('Date', 'bloglex'), 'ID' => __('ID', 'bloglex'), 'title' => __('Title', 'bloglex'), 'rand' => __('Random', 'bloglex'), ), ), 'order' => array( 'type' => 'select', 'std' => 'desc', 'label' => __('Order', 'bloglex'), 'options' => array( 'asc' => __('ASC', 'bloglex'), 'desc' => __('DESC', 'bloglex'), ), ), 'show_counter' => array( 'type' => 'checkbox', 'label' => __('Show Counter', 'bloglex'), 'std' => true, ), 'show_image' => array( 'type' => 'checkbox', 'label' => __('Show Image', 'bloglex'), 'std' => true, ), 'image_size' => array( 'type' => 'select', 'label' => __('Image size', 'bloglex'), 'options' => array( 'thumbnail' => __('Thumbnail', 'bloglex'), 'medium' => __('Medium', 'bloglex'), 'medium_large' => __('Medium Large', 'bloglex'), 'large' => __('Large', 'bloglex'), 'full' => __('Full', 'bloglex'), ), 'std' => 'thumbnail', ), 'image_hover_effects' => array( 'type' => 'select', 'label' => __('Image hover effects', 'bloglex'), 'options' => array( 'hover-effect-shine' => __('Shine', 'bloglex'), 'hover-effect-slide' => __('Slide', 'bloglex'), 'hover-effect-zoom' => __('Zoom', 'bloglex'), ), 'std' => 'hover-effect-shine', ), 'show_date' => array( 'type' => 'checkbox', 'label' => __('Show Date', 'bloglex'), 'std' => true, ), 'date_format' => array( 'type' => 'select', 'label' => __('Date Format', 'bloglex'), 'options' => array( 'format_1' => __('Format 1', 'bloglex'), 'format_2' => __('Format 2', 'bloglex'), ), 'std' => 'format_2', ), 'show_author' => array( 'type' => 'checkbox', 'label' => __('Show Author', 'bloglex'), 'std' => false, ), 'display_author_option' => array( 'type' => 'select', 'label' => __('Author Option', 'bloglex'), 'options' => array( 'with_label' => __('With Label', 'bloglex'), 'with_icon' => __('With Icon', 'bloglex'), 'with_avatar_image' => __('With Avatar Image', 'bloglex'), ), 'std' => 'with_icon', ), 'author_text' => array( 'type' => 'text', 'label' => __('Author Text', 'bloglex'), 'std' => __('By:', 'bloglex'), 'desc' => __('This only works when the "With Label" option is selected under "Author Option"', 'bloglex'), ), 'show_category' => array( 'type' => 'checkbox', 'label' => __('Show Category', 'bloglex'), 'std' => true, ), 'category_text' => array( 'type' => 'text', 'label' => __('Category Text', 'bloglex'), ), 'display_category_option' => array( 'type' => 'select', 'label' => __('Category Option', 'bloglex'), 'options' => array( 'none' => __('None', 'bloglex'), 'has-background' => __('Has dot', 'bloglex'), 'has-text-color' => __('Has text color', 'bloglex'), ), 'std' => 'has-text-color', ), 'number_of_cat' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'std' => 1, 'label' => __('Number of Category to show', 'bloglex'), ), ); } /** * Query the posts and return them. */ protected function get_posts($args, $instance) { $query_args = array( 'posts_per_page' => !empty($instance['number']) ? absint($instance['number']) : $this->settings['number']['std'], 'post_status' => 'publish', 'no_found_rows' => 1, 'orderby' => !empty($instance['orderby']) ? sanitize_text_field($instance['orderby']) : $this->settings['orderby']['std'], 'order' => !empty($instance['order']) ? sanitize_text_field($instance['order']) : $this->settings['order']['std'], 'offset' => !empty($instance['offset']) ? sanitize_text_field($instance['offset']) : $this->settings['offset']['std'], 'ignore_sticky_posts' => 1 ); if ( isset($instance['offset']) && absint($instance['offset']) != 0 ) { $query_args['offset'] = absint($instance['offset']); } if (!empty($instance['category']) && -1 != $instance['category'] && 0 != $instance['category']) { $query_args['tax_query'][] = array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $instance['category'], ); } return new WP_Query(apply_filters('bloglex_recent_posts_query_args', $query_args)); } /** * Output widget content. */ public function widget($args, $instance) { $posts = $this->get_posts($args, $instance); if (!$posts->have_posts()) { return; } echo $args['before_widget']; do_action('bloglex_before_recent_posts_with_image'); if (!empty($instance['title'])) { echo $args['before_title'] . esc_html($instance['title']) . $args['after_title']; } echo '
'; do_action('bloglex_after_recent_posts_with_image'); echo $args['after_widget']; } /** * Render a single post item. */ protected function render_post($instance, $counter) { $counter_class = ''; $style = !empty($instance['style']) ? $instance['style'] : $this->settings['style']['std']; $font_size = !empty($instance['font_size']) ? $instance['font_size'] : $this->settings['font_size']['std']; $font_style = !empty($instance['font_style']) ? $instance['font_style'] : $this->settings['font_style']['std']; $image_size = !empty($instance['image_size']) ? $instance['image_size'] : $this->settings['image_size']['std']; $image_hover_effects = !empty($instance['image_hover_effects']) ? $instance['image_hover_effects'] : $this->settings['image_hover_effects']['std']; $show_counter = !empty($instance['show_counter']) ? $instance['show_counter'] : $this->settings['show_counter']['std']; if ($show_counter) { $counter_class = 'has-post-counter'; } $show_author = !empty($instance['show_author']) ? $instance['show_author'] : $this->settings['show_author']['std']; $author_text = !empty($instance['author_text']) ? $instance['author_text'] : $this->settings['author_text']['std']; $display_author_option = !empty($instance['display_author_option']) ? $instance['display_author_option'] : $this->settings['display_author_option']['std']; $category_text = !empty($instance['category_text']) ? $instance['category_text'] : ''; $display_category_option = !empty($instance['display_category_option']) ? $instance['display_category_option'] : $this->settings['display_category_option']['std']; $number_of_cat = !empty($instance['number_of_cat']) ? absint($instance['number_of_cat']) : $this->settings['number_of_cat']['std']; ?>