default_settings = apply_filters( 'powerkit_widget_posts_settings', array( 'title' => '', 'template' => 'list', 'post_type' => 'post', 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'desc', 'time_frame' => '', 'category' => false, 'post_meta' => array( 'date' ), 'post_meta_compact' => false, 'avoid_duplicate' => false, ) ); $widget_details = array( 'classname' => 'powerkit_widget_posts', 'description' => esc_html__( 'Display a list of your featured posts.', 'powerkit' ), ); parent::__construct( 'powerkit_widget_posts', esc_html__( 'Featured Posts', 'powerkit' ), $widget_details ); } /** * Outputs the content for the current widget instance. * * @param array $args Display arguments including 'before_title', 'after_title', * 'before_widget', and 'after_widget'. * @param array $instance Settings for the current widget instance. */ public function widget( $args, $instance ) { global $pk_posts; global $wp_query; if ( ! $pk_posts ) { $pk_posts = array(); } $params = array_merge( $this->default_settings, $instance ); if ( in_array( 'category', $params['post_meta'], true ) ) { $params['post_meta_category'] = true; } else { $params['post_meta_category'] = false; } $posts_args = array( 'post_type' => $params['post_type'], 'posts_per_page' => $params['posts_per_page'], 'order' => $params['order'], 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, ); if ( $params['category'] ) { $category = $params['category']; $posts_args['cat'] = $category; } // Avoid Duplicate. if ( $params['avoid_duplicate'] ) { $main_posts = array(); if ( isset( $wp_query->posts ) && $wp_query->posts ) { $main_posts = wp_list_pluck( $wp_query->posts, 'ID' ); } if ( $main_posts ) { $posts_args['post__not_in'] = array_merge( $main_posts, $pk_posts ); } else { $posts_args['post__not_in'] = $pk_posts; } } // Post order. $posts_args['orderby'] = $params['orderby']; $type_post_views = powerkit_post_views_enabled(); if ( $type_post_views && ( 'views' === $params['orderby'] || 'post_views' === $params['orderby'] ) ) { $posts_args['orderby'] = $type_post_views; // Don't hide posts without views. $posts_args['views_query']['hide_empty'] = false; } if ( $params['time_frame'] ) { $posts_args['date_query'] = array( array( 'column' => 'post_date_gmt', 'after' => $params['time_frame'] . ' ago', ), ); } $posts = new WP_Query( apply_filters_ref_array( 'powerkit_widget_featured_posts_args', array( $posts_args, & $params ) ) ); if ( $posts->have_posts() ) { // Before Widget. echo $args['before_widget']; // XSS. // Title. if ( $params['title'] ) { echo $args['before_title'] . apply_filters( 'widget_title', wp_kses( $params['title'], 'pk-title' ), $instance, $this->id_base ) . $args['after_title']; // XSS. } // Template. if ( in_array( $params['template'], array( 'list', 'numbered', 'large' ), true ) ) { $class = sprintf( 'pk-widget-posts-template-default pk-widget-posts-template-%s', $params['template'] ); } else { $class = sprintf( 'pk-widget-posts-template-%s', $params['template'] ); } // Number of Posts. $class .= sprintf( ' posts-per-page-%s', (int) $params['posts_per_page'] ); ?>
default_settings, $instance ); $templates = apply_filters( 'powerkit_featured_posts_templates', array() ); ?>

$caption ) { ?>

/>

/>

/>

0 ? '- ' . str_repeat( ' ', $depth * 3 ) : ''; $selected = array_map( 'intval', $args['selected'] ); $cat_name = apply_filters( 'list_cats', $category->name, $category ); $output .= sprintf( '', esc_attr( $depth ), esc_attr( $category->term_id ), esc_html( $pad . $cat_name ), selected( in_array( $category->term_id, $selected, true ), true ) ); $output .= "\n"; } } /** * Register Widget */ function powerkit_widget_init_featured_posts() { register_widget( 'Powerkit_Featured_Posts_Widget' ); } add_action( 'widgets_init', 'powerkit_widget_init_featured_posts' );