widget_cssclass = 'blog_tale widget_tab_posts'; $this->widget_description = __("Displays posts in tab", 'blog-tale'); $this->widget_id = 'blog_tale_tab_posts'; $this->widget_name = __('BT: Tab Posts', 'blog-tale'); $this->settings = array( 'post_settings' => array( 'type' => 'heading', 'label' => __('Post Settings', 'blog-tale'), ), 'number' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'max' => '', 'std' => 3, 'label' => __('Number of posts to show', 'blog-tale'), ), 'image_size' => array( 'type' => 'select', 'label' => __('Image Size', 'blog-tale'), 'options' => blog_tale_get_all_image_sizes(true), 'std' => 'thumbnail', ), 'show_date' => array( 'type' => 'checkbox', 'label' => __('Show Date', 'blog-tale'), 'std' => true, ), 'comment_settings' => array( 'type' => 'heading', 'label' => __('Comment Settings', 'blog-tale'), ), 'show_comment_tab' => array( 'type' => 'checkbox', 'label' => __('Show Comment Tab', 'blog-tale'), 'std' => true, ), 'comments_number' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'max' => '', 'std' => 5, 'label' => __('Number of comments to show', 'blog-tale'), ), ); parent::__construct(); } /** * Query the posts and return them. * @param array $args * @param array $instance * @return WP_Query */ public function get_posts($args, $instance, $type) { $number = !empty($instance['number']) ? absint($instance['number']) : $this->settings['number']['std']; switch ($type) { case 'popular': $query_args = array( 'post_type' => 'post', 'posts_per_page' => $number, 'post_status' => 'publish', 'no_found_rows' => 1, 'ignore_sticky_posts' => 1, 'orderby' => 'comment_count', ); return new WP_Query(apply_filters('blog_tale_popular_posts_query_args', $query_args)); break; case 'recent': $query_args = array( 'post_type' => 'post', 'posts_per_page' => $number, 'post_status' => 'publish', 'no_found_rows' => 1, 'ignore_sticky_posts' => 1, ); return new WP_Query(apply_filters('blog_tale_recent_posts_query_args', $query_args)); break; default: break; } } /** * Outputs the tab posts * * @param array $instance */ public function render_post($instance){ ?>
the_title_attribute( array( 'echo' => false, ) ), ) ); ?>

get_posts($args, $instance, 'recent'); if ($recent_posts->have_posts()) { while ($recent_posts->have_posts()):$recent_posts->the_post(); $this->render_post($instance); endwhile; wp_reset_postdata(); } ?>
absint($instance['comments_number']), 'status' => 'approve', 'post_status' => 'publish' ), $instance)); $output = '
    '; if (is_array($comments) && $comments) { // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.) $post_ids = array_unique(wp_list_pluck($comments, 'comment_post_ID')); _prime_post_caches($post_ids, strpos(get_option('permalink_structure'), '%category%'), false); foreach ((array)$comments as $comment) { $avatar = get_avatar($comment, 60); $comment_text = get_comment_excerpt($comment->comment_ID); $comment_date = get_comment_date('M j, H:i', $comment->comment_ID); $output .= '
  • '; $output .= '
    '; $output .= '
    ' . wp_kses_post($avatar) . '
    '; $output .= '
    '; $output .= '' . get_comment_author_link($comment) . ''; $output .= '' . __('comments on', 'blog-tale') . ''; $output .= '' . get_the_title($comment->comment_post_ID) . ''; $output .= '' . wp_kses_post($comment_text) . ''; $output .= '' . esc_html($comment_date) . ''; $output .= '
    '; $output .= '
    '; $output .= '
  • '; } } $output .= '
'; echo wp_kses_post($output); ?>