public function widget($args, $instance) { if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); $select_week = isset($instance['select_week']) ? $instance['select_week'] : true; $select_month = isset($instance['select_month']) ? $instance['select_month'] : true; $select_year = isset($instance['select_year']) ? $instance['select_year'] : true; $number = !empty($instance['number']) ? absint($instance['number']) : 5; if (!$number) { $number = 5; } $show_thumbnail = isset($instance['show_thumbnail']) ? $instance['show_thumbnail'] : true; echo $args['before_widget']; if ($title) { echo $args['before_title'] . $title . $args['after_title']; } if ($select_week || $select_month || $select_year) { $rand = rand(); $tabs = array(); if ($select_week) { $tabs[] = 'week'; } if ($select_month) { $tabs[] = 'month'; } if ($select_year) { $tabs[] = 'year'; } ?> <div class="kt_widget_tabs"> <ul class="clearfix kt-tabs-nav"> <?php if ($select_week) { ?> <li><a href="#kt_tab_week<?php echo $rand; ?> "><?php esc_html_e('1 Week', 'adroit'); ?> </a></li><?php } ?> <?php if ($select_month) { ?> <li><a href="#kt_tab_month<?php echo $rand; ?> "><?php esc_html_e('1 Month', 'adroit'); ?> </a></li><?php } ?> <?php if ($select_year) { ?> <li><a href="#kt_tab_year<?php echo $rand; ?> "><?php esc_html_e('1 year', 'adroit'); ?> </a></li><?php } ?> </ul> <div class="tabs-container"> <?php if (count($tabs)) { $argsp = array('posts_per_page' => $number, 'ignore_sticky_posts' => true, 'post_status' => 'publish', 'orderby' => 'meta_value_num', 'meta_key' => 'kt_post_views_count'); foreach ($tabs as $tab) { $argsn = $argsp; if ($tab == 'week') { $argsn['date_query'] = array(array('year' => date('Y'), 'week' => date('w'))); } elseif ($tab == 'month') { $argsn['date_query'] = array(array('after' => array('year' => date('Y'), 'month' => date('m') - 1, 'day' => date('d')), 'before' => array('year' => date('Y'), 'month' => date('m'), 'day' => date('d')), 'inclusive' => true)); } elseif ($tab == 'year') { $argsn['date_query'] = array(array('after' => array('year' => date('Y'), 'month' => date('m'), 'day' => date('d')), 'before' => array('year' => date('Y'), 'month' => date('m'), 'day' => date('d')), 'inclusive' => true)); } $query = new WP_Query(apply_filters('widget_posts_args', $argsn)); ?> <div id="kt_tab_<?php echo $tab; echo $rand; ?> " class="kt_tabs_content"> <?php if ($query->have_posts()) { ?> <ul> <?php while ($query->have_posts()) { $query->the_post(); ?> <li <?php post_class('article-widget clearfix'); ?> > <?php if ($show_thumbnail) { kt_post_thumbnail_image('kt_small', 'img-responsive'); } ?> <div class="article-attr"> <h3 class="title"><a href="<?php the_permalink(); ?> "><?php get_the_title() ? the_title() : the_ID(); ?> </a></h3> <div class="entry-meta-data"> <?php kt_entry_date(); kt_get_post_views(); ?> </div> </div> </li> <?php } wp_reset_postdata(); ?> </ul> <?php } ?> </div> <?php } } ?> </div> </div> <?php } echo $args['after_widget']; }
/** * Prints HTML with meta information for the categories, tags. * * Create your own kt_entry_meta() function to override in a child theme. * */ function kt_entry_meta($share = false) { echo '<div class="post-item-meta">'; echo '<div class="post-item-metaleft pull-left">'; kt_entry_meta_author(); kt_entry_date(); echo '</div><!-- .post-item-metaleft -->'; echo '<div class="post-item-metaright pull-right">'; if ($share) { kt_share_box(); } kt_get_post_views(); kt_entry_meta_comments(); echo '</div><!-- .post-item-metaright -->'; echo '<div class="clearfix"></div></div><!-- .post-item-meta -->'; }