'academica-featured-posts-gallery', 'description' => 'Shows the latest posts with a featured image from a category (or all categories).' ); parent::__construct( 'academica-featured-posts-gallery', 'Academica: Featured Posts Gallery', $widget_ops ); add_action( 'save_post', array( &$this, 'flush_widget_cache' ) ); add_action( 'deleted_post', array( &$this, 'flush_widget_cache' ) ); add_action( 'switch_theme', array( &$this, 'flush_widget_cache' ) ); } function widget( $args, $instance ) { $cache = get_transient( 'widget_' . $this->id ); if ( $cache ) { echo $cache; return; } ob_start(); extract( $args, EXTR_SKIP ); $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); $category = absint( $instance['category'] ); $amount = absint( $instance['amount'] ); $display = ( 'grid' == $instance['display'] ) ? 'grid' : 'list'; $count = 0; $query_args = array( // Get more posts than we need, in case there are not enough post thumbnails 'posts_per_page' => $amount * 2, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ); if ( $category ) { $query_args['cat'] = $category; if ( ! empty( $title ) ) { $title = sprintf( '%3$s', esc_url( get_category_link( $category ) ), esc_attr( get_cat_name( $category ) ), sprintf( esc_html_x( '%s »', 'Widget title link', 'academica' ), $title ) ); } } $r = new WP_Query( $query_args ); if ( $r->have_posts() ) { echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; ?> id, $cache ); } } function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['category'] = absint( $new_instance['category'] ); $instance['amount'] = absint( $new_instance['amount'] ); $instance['display'] = ( 'grid' == $new_instance['display'] ) ? 'grid' : 'list'; $this->flush_widget_cache(); return $instance; } function flush_widget_cache() { delete_transient( 'widget_' . $this->id ); } function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'category' => 0, 'amount' => 4, 'display' => 'list' ) ); $title = strip_tags( $instance['title'] ); $category = absint( $instance['category'] ); $amount = absint( $instance['amount'] ); $display = ( 'grid' == $instance['display'] ) ? 'grid' : 'list'; ?>

esc_html__( '- Recent in all categories -', 'academica' ), 'hide_if_empty' => true, 'selected' => $category, 'name' => $this->get_field_name( 'category' ), 'id' => $this->get_field_id( 'category' ), 'class' => 'widefat', 'show_count' => true ) ); ?>