'block2_widget', 'description' => esc_html__( "Block posts widget, best for Home Content Top & Home Content Bottom Sidebar.", 'glob') ); parent::__construct('glob_block_2_widget', esc_html__('FT Block 2', 'glob'), $widget_ops); $this->alt_option_name = 'widget_block2'; } /** * @param array $args * @param array $instance */ public function widget( $args, $instance ) { $instance = wp_parse_args( $instance, array( 'title' => '', 'block_category' => '', 'ignore_sticky' => 1, 'number_posts' => 3, 'order' => 'DESC', 'orderby' => 'date', 'column' => '3' ) ); // Get values from the widget settings. $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); $block_category = (!empty($instance['block_category'])) ? $instance['block_category'] : ''; $ignore_sticky = isset($instance['ignore_sticky']) ? $instance['ignore_sticky'] : 1; $orderby = (!empty($instance['orderby'])) ? $instance['orderby'] : 'date'; $order = (!empty($instance['order'])) ? $instance['order'] : 'DESC'; $number_posts = (!empty($instance['number_posts'])) ? absint($instance['number_posts']) : 3; if ( ! $number_posts ) { $number_posts = 3; } if ( ! $instance['column'] ) { $instance['column'] = 3; } $custom_query_args = array( 'post_type' => 'post', 'posts_per_page' => $number_posts, 'post_status' => 'publish', 'ignore_sticky_posts' => $ignore_sticky, 'category__in' => $block_category, 'order' => $order, 'orderby' => $orderby, 'meta_query' => array(array('key' => '_thumbnail_id')) ); $custom_query = new WP_Query(apply_filters('widget_block_2_posts_args', $custom_query_args)); if ($custom_query->have_posts()) { echo $args['before_widget']; $widget_title = glob_setup_widget_cat_title( $block_category, $title ); if ( $widget_title ) { ?>
'', 'block_category' => '', 'ignore_sticky' => 1, 'number_posts' => 3, 'order' => 'DESC', 'orderby' => 'date', 'column' => '3' ) ); $instance['title'] = sanitize_text_field( $new_instance['title'] ); $instance['ignore_sticky'] = isset($new_instance['ignore_sticky']) && $new_instance['ignore_sticky'] ? 1 : 0; $instance['block_category'] = isset( $new_instance['block_category'] ) ? absint( $new_instance['block_category'] ) : '' ; $instance['number_posts'] = absint( $new_instance['number_posts'] ); $instance['order'] = sanitize_text_field( $new_instance['order'] ); $instance['orderby'] = sanitize_text_field( $new_instance['orderby'] ); $instance['column'] = absint( $new_instance['column'] ); return $instance; } /** * @param array $instance */ public function form( $instance ) { // Set default value. $defaults = array( 'title' => '', 'block_category' => '', 'ignore_sticky' => 1, 'number_posts' => 3, 'order' => 'DESC', 'orderby' => 'date', 'column' => '3' ); $instance = wp_parse_args( (array) $instance, $defaults ); $block_category = $instance['block_category']; $list_categories = get_categories(); $order = array( 'ASC', 'DESC' ); $orderby = array('date', 'comment_count', 'rand'); if ( ! $instance['column'] ) { $instance['column'] = 3; } ?>
/>