29 * @since Twenty Fourteen 1.0 |
28 * @since Twenty Fourteen 1.0 |
30 * |
29 * |
31 * @return Twenty_Fourteen_Ephemera_Widget |
30 * @return Twenty_Fourteen_Ephemera_Widget |
32 */ |
31 */ |
33 public function __construct() { |
32 public function __construct() { |
34 parent::__construct( 'widget_twentyfourteen_ephemera', __( 'Twenty Fourteen Ephemera', 'twentyfourteen' ), array( |
33 parent::__construct( |
35 'classname' => 'widget_twentyfourteen_ephemera', |
34 'widget_twentyfourteen_ephemera', __( 'Twenty Fourteen Ephemera', 'twentyfourteen' ), array( |
36 'description' => __( 'Use this widget to list your recent Aside, Quote, Video, Audio, Image, Gallery, and Link posts.', 'twentyfourteen' ), |
35 'classname' => 'widget_twentyfourteen_ephemera', |
37 ) ); |
36 'description' => __( 'Use this widget to list your recent Aside, Quote, Video, Audio, Image, Gallery, and Link posts.', 'twentyfourteen' ), |
|
37 'customize_selective_refresh' => true, |
|
38 ) |
|
39 ); |
|
40 |
|
41 if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) { |
|
42 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
|
43 } |
|
44 } |
|
45 |
|
46 /** |
|
47 * Enqueue scripts. |
|
48 * |
|
49 * @since Twenty Fourteen 1.7 |
|
50 */ |
|
51 public function enqueue_scripts() { |
|
52 /** This filter is documented in wp-includes/media.php */ |
|
53 $audio_library = apply_filters( 'wp_audio_shortcode_library', 'mediaelement' ); |
|
54 /** This filter is documented in wp-includes/media.php */ |
|
55 $video_library = apply_filters( 'wp_video_shortcode_library', 'mediaelement' ); |
|
56 if ( in_array( 'mediaelement', array( $video_library, $audio_library ), true ) ) { |
|
57 wp_enqueue_style( 'wp-mediaelement' ); |
|
58 wp_enqueue_script( 'mediaelement-vimeo' ); |
|
59 wp_enqueue_script( 'wp-mediaelement' ); |
|
60 } |
38 } |
61 } |
39 |
62 |
40 /** |
63 /** |
41 * Output the HTML for this widget. |
64 * Output the HTML for this widget. |
42 * |
65 * |
43 * @access public |
|
44 * @since Twenty Fourteen 1.0 |
66 * @since Twenty Fourteen 1.0 |
45 * |
67 * |
46 * @param array $args An array of standard parameters for widgets in this theme. |
68 * @param array $args An array of standard parameters for widgets in this theme. |
47 * @param array $instance An array of settings for this widget instance. |
69 * @param array $instance An array of settings for this widget instance. |
48 */ |
70 */ |
82 } |
104 } |
83 |
105 |
84 $number = empty( $instance['number'] ) ? 2 : absint( $instance['number'] ); |
106 $number = empty( $instance['number'] ) ? 2 : absint( $instance['number'] ); |
85 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? $format_string : $instance['title'], $instance, $this->id_base ); |
107 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? $format_string : $instance['title'], $instance, $this->id_base ); |
86 |
108 |
87 $ephemera = new WP_Query( array( |
109 $ephemera = new WP_Query( |
88 'order' => 'DESC', |
110 array( |
89 'posts_per_page' => $number, |
111 'order' => 'DESC', |
90 'no_found_rows' => true, |
112 'posts_per_page' => $number, |
91 'post_status' => 'publish', |
113 'no_found_rows' => true, |
92 'post__not_in' => get_option( 'sticky_posts' ), |
114 'post_status' => 'publish', |
93 'tax_query' => array( |
115 'post__not_in' => get_option( 'sticky_posts' ), |
94 array( |
116 'tax_query' => array( |
95 'taxonomy' => 'post_format', |
117 array( |
96 'terms' => array( "post-format-$format" ), |
118 'taxonomy' => 'post_format', |
97 'field' => 'slug', |
119 'terms' => array( "post-format-$format" ), |
98 'operator' => 'IN', |
120 'field' => 'slug', |
|
121 'operator' => 'IN', |
|
122 ), |
99 ), |
123 ), |
100 ), |
124 ) |
101 ) ); |
125 ); |
102 |
126 |
103 if ( $ephemera->have_posts() ) : |
127 if ( $ephemera->have_posts() ) : |
104 $tmp_content_width = $GLOBALS['content_width']; |
128 $tmp_content_width = $GLOBALS['content_width']; |
105 $GLOBALS['content_width'] = 306; |
129 $GLOBALS['content_width'] = 306; |
106 |
130 |
107 echo $args['before_widget']; |
131 echo $args['before_widget']; |
108 ?> |
132 ?> |
109 <h1 class="widget-title <?php echo esc_attr( $format ); ?>"> |
133 <h1 class="widget-title <?php echo esc_attr( $format ); ?>"> |
110 <a class="entry-format" href="<?php echo esc_url( get_post_format_link( $format ) ); ?>"><?php echo esc_html( $title ); ?></a> |
134 <a class="entry-format" href="<?php echo esc_url( get_post_format_link( $format ) ); ?>"><?php echo esc_html( $title ); ?></a> |
111 </h1> |
135 </h1> |
112 <ol> |
136 <ol> |
113 |
137 |
114 <?php |
138 <?php |
115 while ( $ephemera->have_posts() ) : |
139 while ( $ephemera->have_posts() ) : |
116 $ephemera->the_post(); |
140 $ephemera->the_post(); |
117 $tmp_more = $GLOBALS['more']; |
141 $tmp_more = $GLOBALS['more']; |
118 $GLOBALS['more'] = 0; |
142 $GLOBALS['more'] = 0; |
119 ?> |
143 ?> |
120 <li> |
144 <li> |
121 <article <?php post_class(); ?>> |
145 <article <?php post_class(); ?>> |
122 <div class="entry-content"> |
146 <div class="entry-content"> |
123 <?php |
147 <?php |
124 if ( has_post_format( 'gallery' ) ) : |
148 if ( has_post_format( 'gallery' ) ) : |
125 |
149 |
126 if ( post_password_required() ) : |
150 if ( post_password_required() ) : |
127 the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyfourteen' ) ); |
151 the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyfourteen' ) ); |
128 else : |
152 else : |
129 $images = array(); |
153 $images = array(); |
130 |
154 |
131 $galleries = get_post_galleries( get_the_ID(), false ); |
155 $galleries = get_post_galleries( get_the_ID(), false ); |
132 if ( isset( $galleries[0]['ids'] ) ) |
156 if ( isset( $galleries[0]['ids'] ) ) { |
133 $images = explode( ',', $galleries[0]['ids'] ); |
157 $images = explode( ',', $galleries[0]['ids'] ); |
134 |
158 } |
135 if ( ! $images ) : |
159 |
136 $images = get_posts( array( |
160 if ( ! $images ) : |
137 'fields' => 'ids', |
161 $images = get_posts( |
138 'numberposts' => -1, |
162 array( |
139 'order' => 'ASC', |
163 'fields' => 'ids', |
140 'orderby' => 'menu_order', |
164 'numberposts' => -1, |
|
165 'order' => 'ASC', |
|
166 'orderby' => 'menu_order', |
141 'post_mime_type' => 'image', |
167 'post_mime_type' => 'image', |
142 'post_parent' => get_the_ID(), |
168 'post_parent' => get_the_ID(), |
143 'post_type' => 'attachment', |
169 'post_type' => 'attachment', |
144 ) ); |
170 ) |
145 endif; |
171 ); |
146 |
172 endif; |
147 $total_images = count( $images ); |
173 |
148 |
174 $total_images = count( $images ); |
149 if ( has_post_thumbnail() ) : |
175 |
150 $post_thumbnail = get_the_post_thumbnail(); |
176 if ( has_post_thumbnail() ) : |
|
177 $post_thumbnail = get_the_post_thumbnail(); |
151 elseif ( $total_images > 0 ) : |
178 elseif ( $total_images > 0 ) : |
152 $image = reset( $images ); |
179 $image = reset( $images ); |
153 $post_thumbnail = wp_get_attachment_image( $image, 'post-thumbnail' ); |
180 $post_thumbnail = wp_get_attachment_image( $image, 'post-thumbnail' ); |
154 endif; |
181 endif; |
155 |
182 |
156 if ( ! empty ( $post_thumbnail ) ) : |
183 if ( ! empty( $post_thumbnail ) ) : |
157 ?> |
184 ?> |
158 <a href="<?php the_permalink(); ?>"><?php echo $post_thumbnail; ?></a> |
185 <a href="<?php the_permalink(); ?>"><?php echo $post_thumbnail; ?></a> |
159 <?php endif; ?> |
186 <?php endif; ?> |
160 <p class="wp-caption-text"> |
187 <p class="wp-caption-text"> |
161 <?php |
188 <?php |
162 printf( _n( 'This gallery contains <a href="%1$s" rel="bookmark">%2$s photo</a>.', 'This gallery contains <a href="%1$s" rel="bookmark">%2$s photos</a>.', $total_images, 'twentyfourteen' ), |
189 printf( |
163 esc_url( get_permalink() ), |
190 _n( 'This gallery contains <a href="%1$s" rel="bookmark">%2$s photo</a>.', 'This gallery contains <a href="%1$s" rel="bookmark">%2$s photos</a>.', $total_images, 'twentyfourteen' ), |
164 number_format_i18n( $total_images ) |
191 esc_url( get_permalink() ), |
165 ); |
192 number_format_i18n( $total_images ) |
166 ?> |
193 ); |
|
194 ?> |
167 </p> |
195 </p> |
168 <?php |
196 <?php |
169 endif; |
197 endif; |
170 |
198 |
171 else : |
199 else : |
172 the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyfourteen' ) ); |
200 the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyfourteen' ) ); |
173 endif; |
201 endif; |
174 ?> |
202 ?> |
175 </div><!-- .entry-content --> |
203 </div><!-- .entry-content --> |
176 |
204 |
177 <header class="entry-header"> |
205 <header class="entry-header"> |
178 <div class="entry-meta"> |
206 <div class="entry-meta"> |
179 <?php |
207 <?php |
180 if ( ! has_post_format( 'link' ) ) : |
208 if ( ! has_post_format( 'link' ) ) : |
181 the_title( '<h1 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h1>' ); |
209 the_title( '<h1 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h1>' ); |
182 endif; |
210 endif; |
183 |
211 |
184 printf( '<span class="entry-date"><a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s">%3$s</time></a></span> <span class="byline"><span class="author vcard"><a class="url fn n" href="%4$s" rel="author">%5$s</a></span></span>', |
212 printf( |
185 esc_url( get_permalink() ), |
213 '<span class="entry-date"><a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s">%3$s</time></a></span> <span class="byline"><span class="author vcard"><a class="url fn n" href="%4$s" rel="author">%5$s</a></span></span>', |
186 esc_attr( get_the_date( 'c' ) ), |
214 esc_url( get_permalink() ), |
187 esc_html( get_the_date() ), |
215 esc_attr( get_the_date( 'c' ) ), |
188 esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), |
216 esc_html( get_the_date() ), |
189 get_the_author() |
217 esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), |
190 ); |
218 get_the_author() |
191 |
219 ); |
192 if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) : |
220 |
|
221 if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) : |
193 ?> |
222 ?> |
194 <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyfourteen' ), __( '1 Comment', 'twentyfourteen' ), __( '% Comments', 'twentyfourteen' ) ); ?></span> |
223 <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyfourteen' ), __( '1 Comment', 'twentyfourteen' ), __( '% Comments', 'twentyfourteen' ) ); ?></span> |
195 <?php endif; ?> |
224 <?php endif; ?> |
196 </div><!-- .entry-meta --> |
225 </div><!-- .entry-meta --> |
197 </header><!-- .entry-header --> |
226 </header><!-- .entry-header --> |