__( 'Display News / Advanced Post.', 'best-shop' ), ) ); } public function widget( $args, $instance ) { $max_items = ( ! empty( $instance['max_items'] ) ) ? absint( $instance['max_items'] ) : 6; $category = ( ! empty( $instance['category'] ) ) ? wp_strip_all_tags( $instance['category'] ) : 0; $max_height = (!empty($instance['max_height'])) ? absint($instance['max_height']) : 300; $title = ( ! empty( $instance['title'] ) ) ? wp_strip_all_tags( $instance['title'] ) : ''; $layout = ( ! empty( $instance['layout'] ) ) ? wp_strip_all_tags( $instance['layout'] ) : 1; $excerpt = (!empty($instance['excerpt'])) ? absint($instance['excerpt']) : ''; $colums = (!empty($instance['colums'])) ? wp_strip_all_tags($instance['colums']) : "col-md-6 col-sm-6 col-lg-6 col-xs-6"; $args = array(); $today = getdate(); if( $category == -1 ){ $args = array ( 'post_type' => 'post', 'posts_per_page'=> $max_items, 'post_status' => 'publish' ); } else if ($category == -2) { $args = array ('post_type' => 'post', 'posts_per_page' => $max_items , 'meta_key' => 'my_post_viewed', 'orderby' => 'meta_value_num', 'order' => 'DESC' , 'post_status' => 'publish' ); } else if ($category == -3) { $args = array ('post_type' => 'post', 'posts_per_page'=> $max_items, 'order' => 'DESC', 'post_status' => 'publish' ); } else { $args = array ( 'post_type' => 'post', 'posts_per_page'=> $max_items, 'cat' => $category ); } $loop = new WP_Query($args ); echo '
'; } public function form( $instance ) { $max_items = ( ! empty( $instance['max_items'] ) ) ? absint( $instance['max_items'] ) : '6'; $category = ( ! empty( $instance['category'] ) ) ? wp_strip_all_tags( $instance['category'] ) : -1; $max_height = (!empty($instance['max_height'])) ? absint($instance['max_height']) : 300; $title = ( ! empty( $instance['title'] ) ) ? wp_strip_all_tags( $instance['title'] ) : ''; $layout = ( ! empty( $instance['layout'] ) ) ? wp_strip_all_tags( $instance['layout'] ) : 1; $excerpt = (!empty($instance['excerpt'])) ? absint($instance['excerpt']) : ''; $colums = (!empty($instance['colums'])) ? wp_strip_all_tags($instance['colums']) : "col-md-6 col-sm-6 col-lg-6 col-xs-6"; //category $args = get_categories( array( 'orderby' => 'name', 'parent' => 0 )); $categories = get_categories( $args ); $category_list = ''; $item = new best_shop_cat(); $item->term_id = '-1'; $item->name = '-- All Categories --'; array_unshift($categories , $item); $item = new best_shop_cat(); $item->term_id = '-2'; $item->name = 'Popular Posts'; array_unshift($categories , $item); $item = new best_shop_cat(); $item->term_id = '-3'; $item->name = 'Latest Posts'; array_unshift($categories , $item); foreach ( $categories as $cat ) { $selected =''; if(($cat->term_id) == $category){ $selected ='Selected=selected'; } $category_list = $category_list.''; } //layout $layout_list = ''; $layouts = array( '1'=> esc_html__('Compact', 'best-shop'), '2'=> esc_html__('Grid', 'best-shop'), '3'=> esc_html__('List', 'best-shop'), '4'=> esc_html__('Small List', 'best-shop'), '5'=> esc_html__('Summery', 'best-shop') ); foreach ( $layouts as $key => $val ) { $selected =''; if( $key == $layout){ $selected ='Selected=selected'; } $layout_list = $layout_list.''; } //columns $product_colums = array( "col-md-12 col-sm-12 col-lg-12 col-xs-12" => 1, "col-md-6 col-sm-6 col-lg-6 col-xs-12" => 2, "col-md-4 col-sm-4 col-lg-4 col-xs-12" => 3, "col-md-3 col-sm-3 col-lg-3 col-xs-12" => 4, "col-sm-2" => 5, "col-md-2 col-sm-2 col-lg-2 col-xs-12" => 6, ); ?>