WordPress.org

Make WordPress Core

Changeset 24093


Ignore:
Timestamp:
04/25/13 07:42:59 (23 months ago)
Author:
markjaquith
Message:

the_post_format_gallery() (and Twenty Thirteen using it).

fixes #24126. props obenland, wonderboymusic.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/twentythirteen/content-gallery.php

    r24033 r24093  
    2525            <?php wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?> 
    2626        <?php else : ?> 
    27             <?php the_content(); ?> 
     27            <?php the_post_format_gallery(); ?> 
    2828        <?php endif; // is_single() ?> 
    2929    </div><!-- .entry-content --> 
  • trunk/wp-includes/media.php

    r24091 r24093  
    22952295 * 
    22962296 * @param string $content A string which might contain image data. 
     2297 * @param boolean $html Whether to return HTML or data 
    22972298 * @param boolean $remove Optional. Whether to remove the found data from the passed content. 
    22982299 * @param int $limit Optional. The number of galleries to return 
    22992300 * @return array A list of galleries, which in turn are a list of their srcs in order 
    23002301 */ 
    2301 function get_content_galleries( &$content, $remove = false, $limit = 0 ) { 
     2302function get_content_galleries( &$content, $html = true, $remove = false, $limit = 0 ) { 
    23022303    $src = ''; 
    23032304    $galleries = array(); 
     
    23142315                $data = shortcode_parse_atts( $shortcode[3] ); 
    23152316                $gallery = do_shortcode_tag( $shortcode ); 
    2316                 preg_match_all( '#src=[\'"](.+?)[\'"]#is', $gallery, $src, PREG_SET_ORDER ); 
    2317                 if ( ! empty( $src ) ) { 
    2318                     foreach ( $src as $s ) 
    2319                         $srcs[] = $s[1]; 
     2317                if ( $html ) { 
     2318                    $galleries[] = $gallery; 
     2319                } else { 
     2320                    preg_match_all( '#src=[\'"](.+?)[\'"]#is', $gallery, $src, PREG_SET_ORDER ); 
     2321                    if ( ! empty( $src ) ) { 
     2322                        foreach ( $src as $s ) 
     2323                            $srcs[] = $s[1]; 
     2324                    } 
     2325 
     2326                    $data['src'] = array_values( array_unique( $srcs ) ); 
     2327                    $galleries[] = $data; 
    23202328                } 
    23212329 
    2322                 $data['src'] = array_values( array_unique( $srcs ) ); 
    2323                 $galleries[] = $data; 
    23242330                if ( $limit > 0 && count( $galleries ) >= $limit ) 
    23252331                    break; 
     
    23372343 * 
    23382344 * @param int $post_id Optional. Post ID. 
     2345 * @param boolean $html Whether to return HTML or data 
    23392346 * @return array A list of arrays, each containing gallery data and srcs parsed 
    23402347 *      from the expanded shortcode 
    23412348 */ 
    2342 function get_post_galleries( $post_id = 0 ) { 
     2349function get_post_galleries( $post_id = 0, $html = true ) { 
    23432350    $post = empty( $post_id ) ? clone get_post() : get_post( $post_id ); 
    23442351    if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' )  ) 
    23452352        return array(); 
    23462353 
    2347     return get_content_galleries( $post->post_content ); 
     2354    return get_content_galleries( $post->post_content, $html ); 
    23482355} 
    23492356 
     
    23622369        return array(); 
    23632370 
    2364     $data = get_content_galleries( $post->post_content ); 
     2371    $data = get_content_galleries( $post->post_content, false ); 
    23652372    return wp_list_pluck( $data, 'src' ); 
    23662373} 
     
    23722379 * 
    23732380 * @param int $post_id Optional. Post ID. 
     2381 * @param boolean $html Whether to return HTML or data 
    23742382 * @return array Gallery data and srcs parsed from the expanded shortcode 
    23752383 */ 
    2376 function get_post_gallery( $post_id = 0 ) { 
     2384function get_post_gallery( $post_id = 0, $html = true ) { 
    23772385    $post = empty( $post_id ) ? clone get_post() : get_post( $post_id ); 
    23782386    if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' ) ) 
    23792387        return array(); 
    23802388 
    2381     $data = get_content_galleries( $post->post_content, false, 1 ); 
     2389    $data = get_content_galleries( $post->post_content, $html, false, 1 ); 
    23822390    return reset( $data ); 
     2391} 
     2392 
     2393/** 
     2394 * Output the first gallery in the current (@global) $post 
     2395 * 
     2396 * @since 3.6.0 
     2397 */ 
     2398function the_post_format_gallery() { 
     2399    echo get_post_gallery(); 
    23832400} 
    23842401 
     
    23922409 */ 
    23932410function get_post_gallery_images( $post_id = 0 ) { 
    2394     $gallery = get_post_gallery( $post_id ); 
     2411    $gallery = get_post_gallery( $post_id, false ); 
    23952412    if ( empty( $gallery['src'] ) ) 
    23962413        return array(); 
Note: See TracChangeset for help on using the changeset viewer.