WordPress.org

Make WordPress Core

Ticket #23620: 23620.4.diff

File 23620.4.diff, 6.2 KB (added by lancewillett, 9 years ago)
  • wp-content/themes/twentythirteen/style.css

     
    16431643        font-weight: bold;
    16441644}
    16451645
     1646.format-image .entry-header {
     1647        max-width: 724px;
     1648}
     1649
     1650.format-image .entry-header img {
     1651        height: auto;
     1652        max-width: 724px;
     1653}
     1654
    16461655.format-image .entry-content .size-full {
    16471656        margin: 0 -60px;
    16481657        max-width: 724px;
     
    18541863        font-weight: 400;
    18551864}
    18561865
     1866.format-video .entry-header {
     1867        max-width: 724px;
     1868}
     1869
    18571870.format-video .entry-meta {
    18581871        color: #220e10;
    18591872}
  • wp-content/themes/twentythirteen/content-image.php

     
    1010
    1111<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    1212        <header class="entry-header">
     13                <?php twentythirteen_post_image(); ?>
     14
    1315                <?php if ( is_single() ) : ?>
    1416                <h1 class="entry-title"><?php the_title(); ?></h1>
    1517                <?php else : ?>
     
    2022        </header><!-- .entry-header -->
    2123
    2224        <div class="entry-content">
    23                 <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentythirteen' ) ); ?>
     25                <?php twentythirteen_split_content(); ?>
    2426                <?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>' ) ); ?>
    2527        </div><!-- .entry-content -->
    2628
  • wp-content/themes/twentythirteen/functions.php

     
    436436        return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );
    437437}
    438438
     439/**
     440 * Echoes the first found video from current post.
     441 *
     442 * @uses twentythirteen_get_split_content
     443 *
     444 * @print HTML
     445 */
     446function twentythirteen_post_video() {
     447        $first_video = twentythirteen_get_split_content( 'url' );
     448
     449        if ( is_array( $first_video ) )
     450                $first_video = $first_video[0];
     451
     452        echo wp_oembed_get( $first_video );
     453}
     454
     455/**
     456 * Echoes the first found image from current post.
     457 *
     458 * @uses twentythirteen_get_split_content
     459 *
     460 * @print HTML
     461 */
     462function twentythirteen_post_image() {
     463        $first_image = twentythirteen_get_split_content( 'url' );
     464
     465        if ( is_array( $first_image ) )
     466                $first_image = array_shift( $first_image );
     467
     468        if ( is_string( $first_image ) ) {
     469                echo '<img' . ' src="' . $first_image .'" alt="" />';
     470/*
     471        @todo Update core functions to return the image HTML instead of just the src attribute value
     472
     473        get_content_images()
     474        get_content_image()
     475
     476        Add an option to return <img /> HTML string instead of just the `src` attribute value.
     477
     478        Or, return the attachment ID if the image string looks like an attachment
     479
     480        That'd be even better -- since we could then use `wp_get_attachment_image()` to output the image instead of a) trusting the returned HTML and b) trying to build the image HTML string from scratch.
     481*/             
     482        } else if ( is_object( $first_image ) ) {
     483                echo wp_get_attachment_image( $first_image->ID, array( 724, 724 ) );
     484        }
     485}
     486
     487/**
     488 * Echoes the post content without the chosen piece of media (video, image, etc).
     489 *
     490 * @uses twentythirteen_get_split_content
     491 *
     492 * @print HTML
     493 */
     494function twentythirteen_split_content() {
     495        echo twentythirteen_get_split_content( 'rest' );
     496}
     497
     498/**
     499 * Finds first media piece in a given post.
     500 *
     501 * 1. Find a URL or media embed in post format meta.
     502 * 2. Find a source element in post content.
     503 * 3. Find an embed in post content.
     504 * 4. Find an attachment.
     505 *
     506 * @param string $return Whether to return the URL or the filtered content.
     507 * @return mixed string: URL of the first media piece found, or the rest of the content without the piece
     508 * or array if finding image attachments.
     509 */
     510function twentythirteen_get_split_content( $return = 'url' ) {
     511        $format       = get_post_format();
     512        $post_content = get_the_content();
     513        $media_item   = '';
     514
     515        if ( 'video' == $format ) {
     516                $post_meta = get_post_format_meta( get_the_ID() );
     517
     518                $media_item = $post_meta['url'];
     519
     520                if ( empty( $media_item ) ) {
     521                        $media_item = $post_meta['media'];
     522
     523                        if ( empty( $media_item ) ) {
     524                                $media_item = get_content_video( $post_content, true );
     525
     526                                if ( empty( $media_item ) ) {
     527                                        $media_item = get_embedded_video( $post_content, true );
     528
     529                                        if ( empty( $media_item ) )
     530                                                $media_item = get_attached_video( get_the_ID() );
     531                                }
     532                        }
     533                }               
     534        } else if ( 'image' == $format ) {
     535                $media_item = get_content_image( $post_content, true );
     536
     537                if ( empty( $media_item ) )
     538                        $media_item = get_attached_images( get_the_ID() );
     539        }
     540
     541        if ( 'rest' === $return )
     542                return $post_content;
     543
     544        return $media_item;
     545}
     546
    439547if ( ! function_exists( 'twentythirteen_featured_gallery' ) ) :
    440548/**
    441549 * Displays first gallery from post content. Changes image size from thumbnail
  • wp-content/themes/twentythirteen/content-video.php

     
    1010
    1111<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    1212        <header class="entry-header">
     13                <?php twentythirteen_post_video(); ?>
     14
    1315                <?php if ( is_single() ) : ?>
    1416                <h1 class="entry-title"><?php the_title(); ?></h1>
    1517                <?php else : ?>
     
    2022        </header><!-- .entry-header -->
    2123
    2224        <div class="entry-content">
    23                 <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentythirteen' ) ); ?>
     25                <?php twentythirteen_split_content(); ?>
    2426                <?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>' ) ); ?>
    2527        </div><!-- .entry-content -->
    2628