esc_html__('This Widget show Post Slide', 'buzmag') ) ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ private function widget_fields() { $buzmag_cat_list[''] = esc_html__('--Choose--','buzmag'); $buzmag_cat_list = buzmag_Category_list(); $fields = array( 'bm_post_slide_title' => array( 'buzmag_widgets_name' => 'bm_post_slide_title', 'buzmag_widgets_title' => esc_html__('Title', 'buzmag'), 'buzmag_widgets_field_type' => 'text', ), 'bm_post_slide_category' => array( 'buzmag_widgets_name' => 'bm_post_slide_category', 'buzmag_widgets_title' => esc_html__('Post Slide Category', 'buzmag'), 'buzmag_widgets_field_type' => 'select', 'buzmag_widgets_field_options' => $buzmag_cat_list, ), 'bm_blog_posts' => array( 'buzmag_widgets_name' => 'bm_blog_posts', 'buzmag_widgets_title' => esc_html__('Blog Posts Number', 'buzmag'), 'buzmag_widgets_field_type' => 'number', ), ); return $fields; } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { extract($args); $bm_post_slide_title = apply_filters( 'widget_title', empty( $instance['bm_post_slide_title'] ) ? '' : $instance['bm_post_slide_title'], $instance, $this->id_base ); $bm_post_slide_category = isset( $instance['bm_post_slide_category'] ) ? $instance['bm_post_slide_category'] : '' ; $bm_blog_posts = isset( $instance['bm_blog_posts'] ) ? $instance['bm_blog_posts'] : '' ; if($bm_blog_posts == ''){ $bm_blog_layout = '-1'; } echo $before_widget; ?>
'post', 'order' => 'DESC', 'posts_per_page' => $bm_blog_posts, 'post_status' => 'publish', 'category_name' => $bm_post_slide_category ); $bm_post_slide_query = new WP_Query($bm_post_slider_args); if (!empty($bm_post_slide_title)): ?>
have_posts()): ?>
have_posts()){ $bm_post_slide_query->the_post(); $buzmag_slider_image = wp_get_attachment_image_src(get_post_thumbnail_id(),'buzmag-slider-img-1');?>
widget_fields(); // Loop through fields foreach ($widget_fields as $widget_field) { extract($widget_field); // Use helper function to get updated field values $instance[$buzmag_widgets_name] = buzmag_widgets_updated_field_value($widget_field, $new_instance[$buzmag_widgets_name]); } return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. * * @uses buzmag_widgets_show_widget_field() defined in widget-fields.php */ public function form($instance) { $widget_fields = $this->widget_fields(); // Loop through fields foreach ($widget_fields as $widget_field) { // Make array elements available as variables extract($widget_field); $buzmag_widgets_field_value = !empty($instance[$buzmag_widgets_name]) ? esc_attr($instance[$buzmag_widgets_name]) : ''; buzmag_widgets_show_widget_field($this, $widget_field, $buzmag_widgets_field_value); } } }