127 | | $images = get_posts( array( |
128 | | 'post_parent' => get_post()->post_parent, |
129 | | 'fields' => 'ids', |
130 | | 'numberposts' => -1, |
131 | | 'post_status' => 'inherit', |
132 | | 'post_type' => 'attachment', |
133 | | 'post_mime_type' => 'image', |
134 | | 'order' => 'ASC', |
135 | | 'orderby' => 'menu_order ID' |
136 | | ) ); |
137 | | $total_images = count( $images ); |
139 | | if ( has_post_thumbnail() ) : |
140 | | $featured_image = get_the_post_thumbnail( get_the_ID(), 'featured-thumbnail-formatted' ); |
141 | | elseif ( $total_images > 0 ) : |
142 | | $image = array_shift( $images ); |
143 | | $featured_image = wp_get_attachment_image( $image, 'featured-thumbnail-formatted' ); |
144 | | endif; |
| 128 | if ( post_password_required() ) : |
| 129 | the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyfourteen' ) ); |
| 130 | else : |
| 131 | $images = array(); |
| 132 | |
| 133 | if ( function_exists( 'get_post_galleries' ) ) { |
| 134 | $galleries = get_post_galleries( get_the_ID(), false ); |
| 135 | if ( isset( $galleries[0]['ids'] ) ) |
| 136 | $images = explode( ',', $galleries[0]['ids'] ); |
| 137 | } else { |
| 138 | $pattern = get_shortcode_regex(); |
| 139 | preg_match( "/$pattern/s", get_the_content(), $match ); |
| 140 | $atts = shortcode_parse_atts( $match[3] ); |
| 141 | if ( isset( $atts['ids'] ) ) |
| 142 | $images = explode( ',', $atts['ids'] ); |
| 143 | } |
| 144 | |
| 145 | if ( ! $images ) : |
| 146 | $images = get_posts( array( |
| 147 | 'fields' => 'ids', |
| 148 | 'numberposts' => 999, |
| 149 | 'order' => 'ASC', |
| 150 | 'orderby' => 'menu_order', |
| 151 | 'post_mime_type' => 'image', |
| 152 | 'post_parent' => get_the_ID(), |
| 153 | 'post_type' => 'attachment', |
| 154 | ) ); |
| 155 | endif; |
| 156 | |
| 157 | $total_images = count( $images ); |
| 158 | |
| 159 | if ( has_post_thumbnail() ) : |
| 160 | $featured_image = get_the_post_thumbnail( get_the_ID(), 'featured-thumbnail-formatted' ); |
| 161 | elseif ( $total_images > 0 ) : |
| 162 | $image = array_shift( $images ); |
| 163 | $featured_image = wp_get_attachment_image( $image, 'featured-thumbnail-formatted' ); |
| 164 | endif; |
| 165 | |
| 166 | if ( ! empty ( $featured_image ) ) : |
146 | | <a href="<?php the_permalink(); ?>"><?php echo $featured_image; ?></a> |
147 | | <p class="wp-caption-text"> |
| 168 | <a href="<?php the_permalink(); ?>"><?php echo $featured_image; ?></a> |
| 169 | <?php |
| 170 | endif; |
| 171 | ?> |
| 172 | <p class="wp-caption-text"> |
| 173 | <?php |
| 174 | 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' ), |
| 175 | esc_url( get_permalink() ), |
| 176 | number_format_i18n( $total_images ) |
| 177 | ); |
| 178 | ?> |
| 179 | </p> |