Make WordPress Core

Ticket #22907: 22907.2.2.diff

File 22907.2.2.diff, 3.4 KB (added by lancewillett, 12 years ago)
  • wp-content/themes/twentyeleven/content-gallery.php

     
    3030                <div class="entry-content">
    3131                        <?php if ( post_password_required() ) : ?>
    3232                                <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?>
    33 
    34                         <?php else : ?>
    35                                 <?php
    36                                         $images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
    37                                         if ( $images ) :
    38                                                 $total_images = count( $images );
    39                                                 $image = array_shift( $images );
    40                                                 $image_img_tag = wp_get_attachment_image( $image->ID, 'thumbnail' );
    41                                 ?>
    42 
     33                        <?php else :
     34                                $images = twentyeleven_get_gallery_images();
     35                                if ( $images ) :
     36                                        $total_images = count( $images );
     37                                        $image = array_shift( $images );
     38                        ?>
    4339                                <figure class="gallery-thumb">
    44                                         <a href="<?php the_permalink(); ?>"><?php echo $image_img_tag; ?></a>
     40                                        <a href="<?php the_permalink(); ?>"><?php echo wp_get_attachment_image( $image, 'thumbnail' ); ?></a>
    4541                                </figure><!-- .gallery-thumb -->
    4642
    4743                                <p><em><?php printf( _n( 'This gallery contains <a %1$s>%2$s photo</a>.', 'This gallery contains <a %1$s>%2$s photos</a>.', $total_images, 'twentyeleven' ),
    4844                                                'href="' . esc_url( get_permalink() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ) ) . '" rel="bookmark"',
    4945                                                number_format_i18n( $total_images )
    5046                                        ); ?></em></p>
    51                         <?php endif; ?>
     47                        <?php endif; // end twentyeleven_get_gallery_images() check ?>
    5248                        <?php the_excerpt(); ?>
    5349                <?php endif; ?>
    5450                <?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
  • wp-content/themes/twentyeleven/functions.php

     
    626626        return $classes;
    627627}
    628628add_filter( 'body_class', 'twentyeleven_body_classes' );
     629
     630/**
     631 * Retrieves the IDs for images in a gallery.
     632 *
     633 * @uses get_post_galleries() first, if available. Falls back to shortcode parsing,
     634 * then as last option uses a get_posts() call.
     635 *
     636 * @since Twenty Eleven 1.6.
     637 *
     638 * @return array List of image IDs from the post gallery.
     639 */
     640function twentyeleven_get_gallery_images() {
     641        $images = array();
     642
     643        if ( function_exists( 'get_post_gallery_images' ) ) {
     644                $galleries = get_post_galleries();
     645                if ( isset( $galleries[0]['ids'] ) )
     646                        $images = explode( ',', $galleries[0]['ids'] );
     647        } else {
     648                $pattern = get_shortcode_regex();
     649                preg_match( "/$pattern/s", get_the_content(), $match );
     650                $atts = shortcode_parse_atts( $match[3] );
     651                if ( isset( $atts['ids'] ) )
     652                        $images = explode( ',', $atts['ids'] );
     653        }
     654
     655        if ( ! $images ) {
     656                $images = get_posts( array(
     657                        'fields'         => 'ids',
     658                        'numberposts'    => 999,
     659                        'order'          => 'ASC',
     660                        'orderby'        => 'menu_order',
     661                        'post_mime_type' => 'image',
     662                        'post_parent'    => get_the_ID(),
     663                        'post_type'      => 'attachment',
     664                ) );
     665        }
     666
     667        return $images;
     668}
     669 No newline at end of file