'widget_twentyfourteen_ephemera', 'description' => __( 'Use this widget to list your recent Aside, Quote, Video, Audio, Image, Gallery, and Link posts', 'twentyfourteen' ), ) ); /* * @todo http://core.trac.wordpress.org/ticket/23257: Add plural versions of Post Format strings */ $this->format_strings = array( 'aside' => __( 'Asides', 'twentyfourteen' ), 'image' => __( 'Images', 'twentyfourteen' ), 'video' => __( 'Videos', 'twentyfourteen' ), 'audio' => __( 'Audio', 'twentyfourteen' ), 'quote' => __( 'Quotes', 'twentyfourteen' ), 'link' => __( 'Links', 'twentyfourteen' ), 'gallery' => __( 'Galleries', 'twentyfourteen' ), ); 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' ) ); } /** * Output the HTML for this widget. * * @access public * @since Twenty Fourteen 1.0 * * @param array $args An array of standard parameters for widgets in this theme. * @param array $instance An array of settings for this widget instance. * @return void Echoes its output. */ public function widget( $args, $instance ) { $format = $instance['format']; $number = empty( $instance['number'] ) ? 2 : absint( $instance['number'] ); $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? $this->format_strings[ $format ] : $instance['title'], $instance, $this->id_base ); $ephemera = new WP_Query( array( 'order' => 'DESC', 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'post__not_in' => get_option( 'sticky_posts' ), 'tax_query' => array( array( 'taxonomy' => 'post_format', 'terms' => array( "post-format-$format" ), 'field' => 'slug', 'operator' => 'IN', ), ), ) ); if ( $ephemera->have_posts() ) : $tmp_content_width = $GLOBALS['content_width']; $GLOBALS['content_width'] = 306; echo $args['before_widget']; ?>

    have_posts() ) : $ephemera->the_post(); ?>
  1. >
    →', 'twentyfourteen' ) ); else : $images = array(); $galleries = get_post_galleries( get_the_ID(), false ); if ( isset( $galleries[0]['ids'] ) ) $images = explode( ',', $galleries[0]['ids'] ); if ( ! $images ) : $images = get_posts( array( 'fields' => 'ids', 'numberposts' => -1, 'order' => 'ASC', 'orderby' => 'menu_order', 'post_mime_type' => 'image', 'post_parent' => get_the_ID(), 'post_type' => 'attachment', ) ); endif; $total_images = count( $images ); if ( has_post_thumbnail() ) : $post_thumbnail = get_the_post_thumbnail(); elseif ( $total_images > 0 ) : $image = array_shift( $images ); $post_thumbnail = wp_get_attachment_image( $image, 'post-thumbnail' ); endif; if ( ! empty ( $post_thumbnail ) ) : ?>

    %2$s photo.', 'This gallery contains %2$s photos.', $total_images, 'twentyfourteen' ), esc_url( get_permalink() ), number_format_i18n( $total_images ) ); ?>

    →', 'twentyfourteen' ) ); endif; ?>
→', 'twentyfourteen' ), $this->format_strings[ $format ] ); ?> formats ) ) { $instance['format'] = $new_instance['format']; } $this->flush_widget_cache(); return $instance; } /** * Delete the transient. * * @since Twenty Fourteen 1.0 * * @return void */ function flush_widget_cache() { delete_transient( $this->id ); } /** * Display the form for this widget on the Widgets page of the Admin area. * * @since Twenty Fourteen 1.0 * * @param array $instance * @return void */ function form( $instance ) { $title = empty( $instance['title'] ) ? '' : esc_attr( $instance['title'] ); $number = empty( $instance['number'] ) ? 2 : absint( $instance['number'] ); $format = isset( $instance['format'] ) && in_array( $instance['format'], $this->formats ) ? $instance['format'] : 'aside'; ?>