esc_html__( 'A Popular Post Widget', 'zeitfresser' ), ) // Args ); } /** * Function to add the post view count */ function zeitfresser_set_views( $post_id ) { if ( in_the_loop() ) { $post_id = get_the_ID(); } else { global $wp_query; $post_id = $wp_query->get_queried_object_id(); } if( is_singular( 'post' ) ) { $count_key = '_daisy_blog_view_count'; $count = get_post_meta( $post_id, $count_key, true ); if( $count == '' ){ $count = 0; delete_post_meta( $post_id, $count_key ); add_post_meta( $post_id, $count_key, '1' ); }else{ $count++; update_post_meta( $post_id, $count_key, $count ); } } } /** * Function to get the post view count */ function zeitfresser_get_views( $post_id ){ $count_key = '_daisy_blog_view_count'; $count = get_post_meta( $post_id, $count_key, true ); if( $count == '' ){ return __( "0 View", 'zeitfresser' ); }elseif($count<=1){ return $count. __(' View', 'zeitfresser' ); }else{ return $count. __(' Views', 'zeitfresser' ); } } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'Popular Posts', 'zeitfresser' ); $num_post = ! empty( $instance['num_post'] ) ? $instance['num_post'] : 3 ; $show_thumbnail = ! empty( $instance['show_thumbnail'] ) ? $instance['show_thumbnail'] : ''; $show_date = ! empty( $instance['show_postdate'] ) ? $instance['show_postdate'] : ''; $based_on = ! empty( $instance['based_on'] ) ? $instance['based_on'] : 'views'; $comment_num = ! empty( $instance['comment_num'] ) ? $instance['comment_num'] : ''; $view_count = ! empty( $instance['view_count'] ) ? $instance['view_count'] : ''; $style = ! empty( $instance['style'] ) ? $instance['style'] : 'style-one'; $cat = get_theme_mod( 'exclude_categories' ); if( $cat ) $cat = array_diff( array_unique( $cat ), array('') ); $arg = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => $num_post, 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, 'category__not_in' => $cat ); if( $based_on == 'views' ){ $arg['orderby'] = 'meta_value_num'; $arg['meta_key'] = '_daisy_blog_view_count'; }elseif( $based_on == 'comments' ){ $arg['orderby'] = 'comment_count'; } $obj = new Graphthemes_Widget_Functions; $daisy_blog_widget_popular_post_size = apply_filters('daisy_blog_widget_popular_post_size', 'thumbnail'); $arg['no_found_rows'] = true; $arg['update_post_meta_cache'] = false; $arg['update_post_term_cache'] = false; $qry = new WP_Query( $arg ); if( $qry->have_posts() ){ echo $args['before_widget']; ob_start(); if( $title ) echo $args['before_title'] . apply_filters( 'widget_title', $title, $instance, $this->id_base ) . $args['after_title']; $target = 'target="_self"'; if( isset($instance['target']) && $instance['target']!='' ) { $target = 'target="_blank"'; } ?>

/>

/>