'', 'supermag_cat' => 0, 'supermag_enable_first_featured'=> 0, 'supermag_post_col_layout' => 0, 'supermag_post_col_first_featured_image_layout' => 'large', 'supermag_post_col_normal_image_layout' => 'large' ); function __construct() { parent::__construct( /*Base ID of your widget*/ 'supermag_posts_col', /*Widget name will appear in UI*/ __('AT Posts Column', 'supermag'), /*Widget description*/ array( 'description' => __( 'Show posts selected category', 'supermag' ), ) ); } /*Widget Backend*/ public function form( $instance ) { /*defaults values*/ $instance = wp_parse_args( (array) $instance, $this->defaults ); /*selected cat*/ $supermag_selected_cat = esc_attr( $instance['supermag_cat'] ); /*Main title*/ $supermag_col_posts_title = esc_attr( $instance['supermag_cat_title'] ); if( empty( $supermag_col_posts_title ) && 0 != $supermag_selected_cat ){ $supermag_col_posts_title = get_cat_name($supermag_selected_cat); } /*Enable first featured*/ $supermag_enable_first_featured = esc_attr( $instance['supermag_enable_first_featured'] ); /*Layout options*/ $supermag_layout_arrays = array( __('Layout 1','supermag'), __('Layout 2','supermag') ); $supermag_post_col_layout = $instance['supermag_post_col_layout']; /*first featured image*/ $supermag_post_col_first_featured_image_layout = $instance['supermag_post_col_first_featured_image_layout']; /*normal featured image*/ $supermag_post_col_normal_image_layout = $instance['supermag_post_col_normal_image_layout']; $choices = supermag_get_image_sizes_options(); ?>

__('From Recent Posts','supermag'), 'orderby' => 'name', 'order' => 'asc', 'show_count' => 1, 'hide_empty' => 1, 'echo' => 1, 'selected' => $supermag_selected_cat, 'hierarchical' => 1, 'name' => $this->get_field_name('supermag_cat'), 'id' => $this->get_field_name('supermag_cat'), 'class' => 'widefat', 'taxonomy' => 'category', 'hide_if_empty' => false, ); wp_dropdown_categories($supermag_dropown_cat); ?>

/>

defaults ); /*selected cat*/ $supermag_selected_cat = esc_attr( $instance['supermag_cat'] ); /*Main title*/ $supermag_col_posts_title = !empty( $instance['supermag_cat_title'] ) ? esc_attr( $instance['supermag_cat_title'] ) : get_cat_name($supermag_selected_cat); $supermag_col_posts_title = apply_filters( 'widget_title', $supermag_col_posts_title, $instance, $this->id_base ); /*Enable first featured*/ $supermag_enable_first_featured = esc_attr( $instance['supermag_enable_first_featured'] ); if( 1 == $supermag_enable_first_featured ){ $supermag_number = 4; } else{ $supermag_number = 6; } $supermag_other_class = ''; if( 'supermag-home' != $supermag_sidebar_id ){ if( 1 != $supermag_enable_first_featured ){ $supermag_number = 3; } if( 'supermag-sidebar') $supermag_other_class = 'supermag-except-home'; } else{ $supermag_other_class = ''; } /*column layout*/ $supermag_post_col_layout = absint( $instance['supermag_post_col_layout'] ); /*first featured post layout*/ $supermag_post_col_first_featured_image_layout = esc_attr( $instance['supermag_post_col_first_featured_image_layout'] ); /*normal featured image*/ $supermag_post_col_normal_image_layout = esc_attr( $instance['supermag_post_col_normal_image_layout'] ); /** * Filter the arguments for the Recent Posts widget. * * @since 1.0.0 * * @see WP_Query * */ $sticky = get_option( 'sticky_posts' ); $supermag_cat_post_args = array( 'posts_per_page' => $supermag_number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'post__not_in' => $sticky ); if( -1 != $supermag_selected_cat ){ $supermag_cat_post_args['cat'] = $supermag_selected_cat; } $supermag_featured_query = new WP_Query($supermag_cat_post_args); if ($supermag_featured_query->have_posts()) : echo $args['before_widget']; if ( !empty( $supermag_col_posts_title ) ){ if( -1 != $supermag_selected_cat ){ echo "
"; } echo $args['before_title'] . $supermag_col_posts_title . $args['after_title']; if( -1 != $supermag_selected_cat ){ echo "
"; } } $supermag_post_col_layout_class =''; if( 1 == $supermag_post_col_layout ){ $supermag_post_col_layout_class = 'sm-col-post-type-2'; } ?> "; // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); endif; } } // Class supermag_posts_col ends here } if ( ! function_exists( 'supermag_posts_col' ) ) : /** * Function to Register and load the widget * * @since 1.0.0 * * @param null * @return void * */ function supermag_posts_col() { register_widget( 'supermag_posts_col' ); } endif; add_action( 'widgets_init', 'supermag_posts_col' );