function widget($args, $instance)
        {
            $cache = wp_cache_get('widget_top_reviews', 'widget');
            if (!is_array($cache)) {
                $cache = array();
            }
            if (!isset($args['widget_id'])) {
                $args['widget_id'] = $this->id;
            }
            if (isset($cache[$args['widget_id']])) {
                echo $cache[$args['widget_id']];
                return;
            }
            ob_start();
            extract($args);
            $cb_title = empty($instance['title']) ? '' : $instance['title'];
            $cb_category = empty($instance['category']) ? '' : $instance['category'];
            $cb_filter = empty($instance['filter']) ? '' : $instance['filter'];
            $cb_sortby = empty($instance['sortby']) ? '' : $instance['sortby'];
            $cb_size = empty($instance['cb_size']) ? 'cb-article-small' : $instance['cb_size'];
            $cb_type = empty($instance['type']) ? '' : $instance['type'];
            $cb_cpt_output = cb_get_custom_post_types();
            if ($cb_filter == NULL) {
                $cb_filter = 'alltime';
            }
            if (empty($instance['number']) || !($number = absint($instance['number']))) {
                $number = 5;
            }
            if ($cb_category != 'cb-all') {
                $cb_cat_qry = $cb_category;
            } else {
                $cb_cat_qry = NULL;
            }
            if ($cb_type == 'cb-reader-score') {
                $cb_type_filter = 'cb_user_score_output';
            } else {
                $cb_type_filter = 'cb_final_score';
            }
            if ($cb_sortby == 'topscores') {
                $cb_sortby_orderby = 'meta_value_num';
                $cb_sortby_order = 'DESC';
            } elseif ($cb_sortby == 'latestscores') {
                $cb_sortby_order = 'DESC';
                $cb_sortby_orderby = 'date';
            } elseif ($cb_sortby == 'lowestscores') {
                $cb_sortby_orderby = 'meta_value_num';
                $cb_sortby_order = 'ASC';
            }
            if ($cb_filter == 'week') {
                $cb_week = date('W');
                $cb_year = date('Y');
                $cb_qry = new WP_Query(array('post_type' => $cb_cpt_output, 'posts_per_page' => $number, 'category_name' => $cb_cat_qry, 'year' => $cb_year, 'w' => $cb_week, 'no_found_rows' => true, 'post_status' => 'publish', 'meta_key' => $cb_type_filter, 'orderby' => $cb_sortby_orderby, 'order' => $cb_sortby_order, 'ignore_sticky_posts' => true));
            } elseif ($cb_filter == 'alltime') {
                $cb_qry = new WP_Query(array('post_type' => $cb_cpt_output, 'posts_per_page' => $number, 'category_name' => $cb_cat_qry, 'no_found_rows' => true, 'post_status' => 'publish', 'meta_key' => $cb_type_filter, 'orderby' => $cb_sortby_orderby, 'order' => $cb_sortby_order, 'ignore_sticky_posts' => true));
            } elseif ($cb_filter == 'month') {
                $cb_month = date('m', strtotime('-30 days'));
                $cb_year = date('Y', strtotime('-30 days'));
                $cb_qry = new WP_Query(array('post_type' => $cb_cpt_output, 'posts_per_page' => $number, 'category_name' => $cb_cat_qry, 'year' => $cb_year, 'monthnum' => $cb_month, 'no_found_rows' => true, 'post_status' => 'publish', 'meta_key' => $cb_type_filter, 'orderby' => $cb_sortby_order, 'order' => $cb_sortby_orderby, 'ignore_sticky_posts' => true));
            } elseif ($cb_filter == '2011' || $cb_filter == '2012' || $cb_filter == '2013' || $cb_filter == '2014' || $cb_filter == '2015') {
                $cb_qry = new WP_Query(array('post_type' => $cb_cpt_output, 'posts_per_page' => $number, 'category_name' => $cb_cat_qry, 'year' => $cb_filter, 'no_found_rows' => true, 'post_status' => 'publish', 'meta_key' => $cb_type_filter, 'orderby' => $cb_sortby_orderby, 'order' => $cb_sortby_order, 'ignore_sticky_posts' => true));
            }
            if ($cb_qry->have_posts()) {
                echo $before_widget;
                if ($cb_title != NULL) {
                    echo $before_title . esc_html($cb_title) . $after_title;
                }
                echo '<div class="cb-module-block">';
                $i = 1;
                while ($cb_qry->have_posts()) {
                    $cb_qry->the_post();
                    global $post;
                    $cb_post_id = $post->ID;
                    $cb_review_checkbox = get_post_meta($cb_post_id, 'cb_review_checkbox', true);
                    if ($cb_review_checkbox != 'on') {
                        continue;
                    }
                    if ($cb_size == 'cb-article-small') {
                        $cb_width = '100';
                        $cb_height = '65';
                        $cb_style = ' cb-separated';
                        $cb_small_box = true;
                    }
                    if ($cb_size == 'cb-article-big') {
                        $cb_width = '360';
                        $cb_height = '240';
                        $cb_small_box = false;
                        $cb_style = ' cb-meta-style-r';
                    }
                    ?>
                    <article class="cb-article <?php 
                    echo esc_attr($cb_size) . ' ' . esc_attr($cb_style);
                    ?>
 clearfix">

                        <div class="cb-meta">
                            <h4 class="cb-post-title"><a href="<?php 
                    the_permalink();
                    ?>
"><?php 
                    the_title();
                    ?>
</a></h4>
                            <?php 
                    cb_review_byline($cb_post_id);
                    ?>
                        
                        </div>
                        <?php 
                    if ($cb_type == 'cb-article-big') {
                        echo '<a href="' . get_the_permalink() . '" class="cb-link"></a>';
                    }
                    ?>
                    </article>
<?php 
                    $i++;
                }
                echo '</div>';
                echo $after_widget;
                wp_reset_postdata();
            }
            $cache[$args['widget_id']] = ob_get_flush();
            wp_cache_set('widget_top_reviews', $cache, 'widget');
        }
        }
        $i++;
        if ($i == 1) {
            echo '<div class="cb-module-r cb-module-block cb-module-half clearfix">' . $cb_title_header;
        }
        ?>
            <article class="cb-article-small cb-article-small-review cb-separated clearfix" role="article">

                <div class="cb-meta">

                    <h2 class="cb-post-title"><a href="<?php 
        the_permalink();
        ?>
"><?php 
        the_title();
        ?>
</a></h2>
                    <?php 
        cb_review_byline($cb_post_id);
        ?>
  

                </div>

            </article>

            <?php 
    }
    echo '</div>';
}
wp_reset_postdata();