'block1_widget', 'description' => esc_html__("Block posts widget, best for Home Content Top & Home Content Bottom Sidebar.", 'glob') ); parent::__construct('glob_block_1_widget', esc_html__('FT Block 1', 'glob'), $widget_ops); $this->alt_option_name = 'widget_block1'; } /** * @param array $args * @param array $instance */ public function widget( $args, $instance ) { // 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'] ) : 7; if ( ! $number_posts ) { $number_posts = 7; } $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, ); $custom_query = new WP_Query( apply_filters( 'widget_block_1_posts_args', $custom_query_args ) ); if ($custom_query->have_posts()) { $n = count( $custom_query->posts ); $count = 0; echo $args['before_widget']; $widget_title = glob_setup_widget_cat_title( $block_category, $title ); if ( $widget_title ) { ?>
'.$widget_title['title'].''; } else { ?>
have_posts()) { $custom_query->the_post(); $count++; if ($count == 1) { ?>
'', 'block_category' => '', 'ignore_sticky' => 1, 'number_posts' => 7, 'order' => 'DESC', 'orderby' => 'date' ) ); $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'] ); return $instance; } /** * @param array $instance */ public function form( $instance ) { // Set default value. $defaults = array( 'title' => '', 'block_category' => '', 'ignore_sticky' => 1, 'number_posts' => 7, 'order' => 'DESC', 'orderby' => 'date' ); $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'); ?>

/>