widget_cssclass = 'blogbull-widget-jumbo-post'; $this->widget_description = __("Jumbo Widget transforms your posts into a visually appealing mosaic, creating a stylish and organized showcase for an immersive reader experience.", 'blogbull'); $this->widget_id = 'Blogbull_Jumbo_Widget'; $this->widget_name = __('BlogBull: Jumbo Post', 'blogbull'); $this->settings = $this->get_widget_settings(); parent::__construct(); } /** * Define widget settings. */ protected function get_widget_settings() { return array( 'title' => array( 'type' => 'text', 'label' => __('Title', 'blogbull'), ), 'layout_style' => array( 'type' => 'select', 'label' => __('Style Layout', 'blogbull'), 'options' => array( 'jumbo-layout-1' => __('Layout 1', 'blogbull'), 'jumbo-layout-2' => __('Layout 2', 'blogbull'), 'jumbo-layout-3' => __('Layout 3', 'blogbull'), ), 'std' => 'jumbo-layout-1', ), 'offset' => array( 'type' => 'number', 'step' => 1, 'min' => 0, 'max' => '', 'std' => '', 'label' => __('Offset', 'blogbull'), '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.', 'blogbull'), ), 'category' => array( 'type' => 'dropdown-taxonomies', 'label' => __('Select Category', 'blogbull'), 'desc' => __('Leave empty if you don\'t want the posts to be category specific', 'blogbull'), 'args' => array( 'taxonomy' => 'category', 'class' => 'widefat', 'hierarchical' => true, 'show_count' => 1, 'show_option_all' => __('— Select —', 'blogbull'), ), ), 'show_category' => array( 'type' => 'checkbox', 'label' => __('Show Category', 'blogbull'), 'std' => true, ), 'category_text' => array( 'type' => 'text', 'label' => __('Category Text', 'blogbull'), ), 'display_category_option' => array( 'type' => 'select', 'label' => __('Category Option', 'blogbull'), 'options' => array( 'none' => __('None', 'blogbull'), 'has-background' => __('Has background', 'blogbull'), 'has-text-color' => __('Has text color', 'blogbull'), ), 'std' => 'has-text-color', ), 'number_of_cat' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'std' => 1, 'label' => __('Number of Category to show', 'blogbull'), ), 'show_date' => array( 'type' => 'checkbox', 'label' => __('Show Date', 'blogbull'), 'std' => true, ), 'date_format' => array( 'type' => 'select', 'label' => __('Date Format', 'blogbull'), 'options' => array( 'format_1' => __('Format 1', 'blogbull'), 'format_2' => __('Format 2', 'blogbull'), ), 'std' => 'format_2', ), 'show_author' => array( 'type' => 'checkbox', 'label' => __('Show Author', 'blogbull'), 'std' => true, ), 'display_author_option' => array( 'type' => 'select', 'label' => __('Author Option', 'blogbull'), 'options' => array( 'with_label' => __('With Label', 'blogbull'), 'with_icon' => __('With Icon', 'blogbull'), 'with_avatar_image' => __('With Avatar Image', 'blogbull'), ), 'std' => 'with_icon', ), 'author_text' => array( 'type' => 'text', 'label' => __('Author Text', 'blogbull'), 'std' => __('By:', 'blogbull'), 'desc' => __('This only works when the "With Label" option is selected under "Author Option"', 'blogbull'), ), ); } /** * Query the posts and return them. * @param array $args * @param array $instance * @return WP_Query */ public function get_posts($args, $instance) { $post_count = ""; switch ($instance['layout_style']) { case "jumbo-layout-1": $post_count = "5"; break; case "jumbo-layout-2": $post_count = "2"; break; case "jumbo-layout-3": $post_count = "9"; break; default: $post_count = ""; } $query_args = array( 'post_status' => 'publish', 'posts_per_page' => $post_count, 'no_found_rows' => 1, '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('Blogbull_Jumbo_Widget_query_args', $query_args)); } /** * Output widget. * * @param array $args * @param array $instance * @see WP_Widget */ public function widget($args, $instance) { ob_start(); echo $args['before_widget']; do_action('blogbull_before_jumbo_widget'); $counter = 1; // Provide a default value for $instance['title'] $title = isset($instance['title']) ? esc_html($instance['title']) : ''; $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']; $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']; if (($posts = $this->get_posts($args, $instance)) && $posts->have_posts()) { ?>

have_posts()): $posts->the_post(); // Set image and title classes based on the post's position $image_class = ($counter == 1) ? "entry-image-large" : (($counter == 2 || $counter == 3) ? "entry-image-small" : ""); $title_class = ($counter == 1) ? "entry-title-big" : "entry-title-small"; // Determine if we need to open or close the right container if ($counter == 1) echo '
'; if ($counter == 2) echo '
'; if ($counter == 4) echo '
'; $article_class = ''; switch ($counter) { case "1": $article_class = "wpi-post-default"; break; case "2": $article_class = "wpi-post-default"; break; case "3": $article_class = "wpi-post-default"; break; case "4": $article_class = "wpi-post-list"; break; case "5": $article_class = "wpi-post-list"; break; default: $article_class = ""; } ?>
have_posts()): $posts->the_post(); $image_class = "entry-image-large"; $title_class = "entry-title-big"; ?>
have_posts()): $posts->the_post(); ?> '; if ($counter == 4) echo '
'; $article_class = 'wpi-post-jumbo wpi-post-jumbo-' . $counter; $article_class .= ($counter <= 3) ? " wpi-post-default" : " wpi-post-list"; ?>