*/ global $apptivo_recent_products; $recent_products_defaults = array( 'title' => 'Recent Products', 'posts_number' => '5', 'order_by' => 'none', 'display_title' => 'true', 'display_content' => 'true', 'display_featured_image' => 'true', 'display_read_more' => 'true', 'display_featured_products' => 'no', 'content_type' => 'the_excerpt', 'excerpt_length' => '26', 'featured_image_width' => '90', 'featured_image_height' => '60', 'featured_image_align' => 'alignleft', 'filter' => 'recent', 'filter_cats' => '' ); $apptivo_recent_products->options['widgets_options']['Products'] = is_array($apptivo_recent_products->options['widgets_options']['Products']) ? array_merge($recent_products_defaults, $apptivo_recent_products->options['widgets_options']['Products']) : $recent_products_defaults; class apptivo_ecommerce_Widget_Recent_Products extends WP_Widget { function __construct() { $widget_options = array('description' => __('Displaying the recent products or Products from the selected categories.', 'themater') ); $control_options = array( 'width' => 500); $this->WP_Widget('apptivo_recent_products','[Apptivo] Recent Products', $widget_options, $control_options); } function widget($args, $instance) { if( !($instance['display_title']) && !($instance['display_content']) ) { $instance['display_title'] = true; } global $apptivo_recent_products; extract( $args ); $title = apply_filters('widget_title', $instance['title']); $post_args = array(); if ( !empty($instance['title']) ) $title = $instance['title']; else $title = __('Recent Products', 'apptivo_ecommerce'); $title = apply_filters('widget_title', $title, $instance, $this->id_base); switch ($instance['order_by']) { case 'none' : $post_args = ''; break; case 'id_asc' : $post_args['orderby'] = 'ID'; $post_args['order'] = 'ASC'; break; case 'id_desc' : $post_args['orderby'] = 'ID'; $post_args['order'] = 'DESC'; break; case 'date_asc' : $post_args['orderby'] = 'date'; $post_args['order'] = 'ASC'; break; case 'date_desc' : $post_args['orderby'] = 'date'; $post_args['order'] = 'DESC'; break; case 'title_asc' : $post_args['orderby'] = 'title'; $post_args['order'] = 'ASC'; break; case 'title_desc' : $post_args['orderby'] = 'title'; $post_args['order'] = 'DESC'; break; default : $post_args['orderby'] = $instance['order_by']; } switch ($instance['filter']) { case 'cats' : $post_args['tax_query'] = array( array( 'taxonomy' => 'item_cat', 'terms' => explode(',',(trim($instance['filter_cats']))), 'field' => 'id', )); break; case 'category' : $post_args['tax_query'] = array( array( 'taxonomy' => 'item_cat', 'terms' => array(trim($instance['selected_category'])), 'field' => 'id', )); break; default : $filter_query = ''; } $post_args['post_type'] = 'item'; $post_args['posts_per_page']=$instance['posts_number']; if($instance['display_featured_products'] == 'yes') { $post_args['meta_query'] = array( array('key' => '_apptivo_featured','value' => 'yes','compare' => '=','type' => 'CHAR'), array('key' => '_apptivo_enabled','value' => 'yes','compare' => '=','type' => 'CHAR') ); }else{ $post_args['meta_query'] = array( array('key' => '_apptivo_enabled','value' => 'yes','compare' => '=','type' => 'CHAR') ); } query_posts($post_args); if ( have_posts() ) : echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; ?>
options['widgets_options']['Products'] ); ?>