Twenty Fourteen: Fix gallery posts in the ephemera widget. Props iamtakashi, fixes #25740.

git-svn-id: https://develop.svn.wordpress.org/trunk@25970 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Lance Willett 2013-10-28 17:52:45 +00:00
parent bd5ac31911
commit 01a703070b
2 changed files with 55 additions and 52 deletions

View File

@ -6,34 +6,10 @@
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
if ( has_post_thumbnail() ) :
$image = get_post_thumbnail_id();
else :
$images = get_posts( array(
'post_parent' => get_the_ID(),
'fields' => 'ids',
'numberposts' => 1,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ID',
) );
$image = array_shift( $images );
endif;
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( is_single() && $image ) : ?>
<div class="featured-thumbnail">
<?php echo wp_get_attachment_image( $image, 'featured-thumbnail-large' ); ?>
</div>
<?php elseif ( $image ) : ?>
<a class="featured-thumbnail" href="<?php the_permalink(); ?>" rel="<?php the_ID(); ?>">
<?php echo wp_get_attachment_image( $image, 'featured-thumbnail-large' ); ?>
</a>
<?php endif; ?>
<?php twentyfourteen_post_thumbnail(); ?>
<header class="entry-header">
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ) ) && twentyfourteen_categorized_blog() ) : ?>

View File

@ -120,39 +120,66 @@ class Twenty_Fourteen_Ephemera_Widget extends WP_Widget {
<?php while ( $ephemera->have_posts() ) : $ephemera->the_post(); ?>
<li>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<article <?php post_class(); ?>>
<div class="entry-content">
<?php
if ( has_post_format( 'gallery' ) ) :
$images = get_posts( array(
'post_parent' => get_post()->post_parent,
'fields' => 'ids',
'numberposts' => -1,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ID'
) );
$total_images = count( $images );
if ( has_post_thumbnail() ) :
$featured_image = get_the_post_thumbnail( get_the_ID(), 'featured-thumbnail-formatted' );
elseif ( $total_images > 0 ) :
$image = array_shift( $images );
$featured_image = wp_get_attachment_image( $image, 'featured-thumbnail-formatted' );
endif;
if ( post_password_required() ) :
the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyfourteen' ) );
else :
$images = array();
if ( function_exists( 'get_post_galleries' ) ) {
$galleries = get_post_galleries( get_the_ID(), false );
if ( isset( $galleries[0]['ids'] ) )
$images = explode( ',', $galleries[0]['ids'] );
} else {
$pattern = get_shortcode_regex();
preg_match( "/$pattern/s", get_the_content(), $match );
$atts = shortcode_parse_atts( $match[3] );
if ( isset( $atts['ids'] ) )
$images = explode( ',', $atts['ids'] );
}
if ( ! $images ) :
$images = get_posts( array(
'fields' => 'ids',
'numberposts' => 999,
'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() ) :
$featured_image = get_the_post_thumbnail( get_the_ID(), 'featured-thumbnail-formatted' );
elseif ( $total_images > 0 ) :
$image = array_shift( $images );
$featured_image = wp_get_attachment_image( $image, 'featured-thumbnail-formatted' );
endif;
if ( ! empty ( $featured_image ) ) :
?>
<a href="<?php the_permalink(); ?>"><?php echo $featured_image; ?></a>
<p class="wp-caption-text">
<a href="<?php the_permalink(); ?>"><?php echo $featured_image; ?></a>
<?php
endif;
?>
<p class="wp-caption-text">
<?php
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' ),
esc_url( get_permalink() ),
number_format_i18n( $total_images )
);
?>
</p>
<?php
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' ),
esc_url( get_permalink() ),
number_format_i18n( $total_images )
);
?>
</p>
<?php
endif;
else :
the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyfourteen' ) );
endif;