Version: 1.0 Author URI: https://www.html5arena.com/ */ class ARENA_Widget_Smart_List extends WP_Widget { public function __construct() { $widget_ops = array( 'classname' => 'arenawidget_smart_entries', 'description' => __( 'Your site’s most recent Posts.' ), 'customize_selective_refresh' => true, ); parent::__construct( 'arena-smart-lists', __( 'Arena Smart Lists' ), $widget_ops ); $this->alt_option_name = 'widget_smart_entries'; } public function widget( $args, $instance ) { if ( ! isset( $args['widget_id'] ) ) { $args['widget_id'] = $this->id; } $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' ); $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5; if ( ! $number ) $number = 5; $hide_img = isset( $instance['hide_img'] ) ? $instance['hide_img'] : false; $hide_onblog = isset( $instance['hide_onblog'] ) ? $instance['hide_onblog'] : false; $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false; $query_type = (!empty( $instance['query_type'] )) ? $instance['query_type'] : 'Recent'; /* This global var is for collecting the post IDs for posts so that post will */ /* not be repeated when multi widgets are used */ global $arena_cnt; $qargs = array ('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true); if (get_the_ID() !== false) { $post_id = get_the_ID(); $arena_cnt[] = get_the_ID(); $qargs ['post__not_in'] = $arena_cnt; } if ($query_type == 'Related') { $cats = get_the_category(); if ( ! empty( $cats ) ) { $first_cat = $cats[0]->term_id; $qargs['category__in'] = array($first_cat); } } else if ($query_type == 'Popular') { $qargs['meta_key' ]= 'post_views'; $qargs['orderby'] = 'meta_value_num' ; $qargs['order'] = 'DESC'; } else if ($query_type == 'Trending') { $qargs['meta_key' ]= 'post_view_7days'; $qargs['orderby'] = 'meta_value_num' ; $qargs['order'] = 'DESC'; } $hide_blog = false; if (is_home() && $hide_onblog == true) $hide_blog = true; if ($hide_blog == false) { $r = new WP_Query( apply_filters( 'widget_posts_args', $qargs) ); if ($r->have_posts()) : ?>

id="get_field_id( 'show_date' ); ?>" name="get_field_name( 'show_date' ); ?>" />

id="get_field_id( 'hide_img' ); ?>" name="get_field_name( 'hide_img' ); ?>" />

id="get_field_id( 'hide_onblog' ); ?>" name="get_field_name( 'hide_onblog' ); ?>" />

.arenawidget_smart_entries ul li:hover img{opacity:0.7}.arenawidget_smart_entries ul li img {float:left;margin-right:0.5em;margin-top:4px;width:100px;height:70px;}.arenawidget_smart_entries ul li {min-height:92px;font-size:90%} "; } add_action('wp_footer', 'arena_ajax_footer', 100); function arena_ajax_footer() { if (is_single() && !is_admin()) { echo ""; } } add_action( 'wp_ajax_nopriv_post_arena_add_view', 'post_arena_add_view' ); add_action( 'wp_ajax_post_arena_add_view', 'post_arena_add_view' ); function post_arena_add_view() { $post_id = -1; if (is_int($_POST['post_id'])) $post_id = $_POST['post_id']; if ($post_id == -1) return; $views = get_post_meta( $post_id, 'post_views', true ); $views++; if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { update_post_meta( $post_id, 'post_views', $views ); echo $views; } $last_view = get_post_meta( $post_id, 'last_view', true ); $last7days = get_post_meta( $post_id, 'last7days', true ); if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { if ($last_view == date("Y/m/d")) { $total7days = 1; if (empty ($last7days)) $last7days = "1,0,0,0,0,0,0"; else { $total7days = 0; $last7counts = explode (",",$last7days); $last7counts[0] ++; for ($t=0;$tdiff($date1)->format("%a"); if ($diff < 7) { $olast7days = explode (',',$last7days); $last7days = "1,"; $total7days = 0; for ($x=1; $x<6; $x++) { if ( $x < $diff ) {$last7days .= '0,';} else { $last7days.= $olast7days[intval($x-$diff)] .','; $total7days += $olast7days[$x-$diff];} } if (6 < $diff) { $last7days.='0';} else { $last7days .= $olast7days[6-$diff];$total7days += $olast7days[6-$diff];} update_post_meta( $post_id, 'post_view_7days', $total7days ); update_post_meta( $post_id, 'last7days',$last7days ); } } update_post_meta( $post_id, 'last_view', date ("Y/m/d") ); } } die(); } ?>