Make WordPress Core


Ignore:
Timestamp:
03/27/2013 06:34:59 PM (12 years ago)
Author:
markjaquith
Message:

Give themers tangible, user-friendly template functions to take full advantage of structured post formats.

  • the_audio()
  • the_video()
  • the_image()
  • get_the_media()

Also introduces:

  • get_the_extra_content()
  • the_extra_content()

Those two functions are like their non-extra versions, except that they
will have any post-format bits extracted. e.g. It's an image post, for
which the_image() will extract an <img /> tag. the_extra_content() will
output the content *without* that image.

props wonderboymusic. Herculean effort. fixes #23572

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post-template.php

    r23769 r23819  
    160160 *
    161161 * @param string $more_link_text Optional. Content for when there is more text.
    162  * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
    163  */
    164 function the_content($more_link_text = null, $stripteaser = false) {
    165     $content = get_the_content($more_link_text, $stripteaser);
    166     $content = apply_filters('the_content', $content);
    167     $content = str_replace(']]>', ']]&gt;', $content);
    168     echo $content;
     162 * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
     163 */
     164function the_content( $more_link_text = null, $strip_teaser = false ) {
     165    $content = apply_filters( 'the_content', get_the_content( $more_link_text, $strip_teaser ) );
     166    echo str_replace( ']]>', ']]&gt;', $content );
    169167}
    170168
     
    178176 * @return string
    179177 */
    180 function get_the_content( $more_link_text = null, $stripteaser = false ) {
     178function get_the_content( $more_link_text = null, $strip_teaser = false ) {
    181179    global $more, $page, $pages, $multipage, $preview;
    182180
     
    187185
    188186    $output = '';
    189     $hasTeaser = false;
     187    $has_teaser = false;
     188    $matches = array();
    190189
    191190    // If post password required and it doesn't match the cookie.
     
    193192        return get_the_password_form();
    194193
    195     if ( $page > count($pages) ) // if the requested page doesn't exist
    196         $page = count($pages); // give them the highest numbered page that DOES exist
    197 
    198     $content = $pages[$page-1];
    199     if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
    200         $content = explode($matches[0], $content, 2);
    201         if ( !empty($matches[1]) && !empty($more_link_text) )
    202             $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1])));
    203 
    204         $hasTeaser = true;
     194    if ( $page > count( $pages ) ) // if the requested page doesn't exist
     195        $page = count( $pages ); // give them the highest numbered page that DOES exist
     196
     197    $content = $pages[$page - 1];
     198    if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
     199        $content = explode( $matches[0], $content, 2 );
     200        if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) )
     201            $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
     202
     203        $has_teaser = true;
    205204    } else {
    206         $content = array($content);
    207     }
    208     if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) )
    209         $stripteaser = true;
     205        $content = array( $content );
     206    }
     207
     208    if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) )
     209        $strip_teaser = true;
     210
    210211    $teaser = $content[0];
    211     if ( $more && $stripteaser && $hasTeaser )
     212
     213    if ( $more && $strip_teaser && $has_teaser )
    212214        $teaser = '';
     215
    213216    $output .= $teaser;
    214     if ( count($content) > 1 ) {
     217
     218    if ( count( $content ) > 1 ) {
    215219        if ( $more ) {
    216220            $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1];
    217221        } else {
    218             if ( ! empty($more_link_text) )
     222            if ( ! empty( $more_link_text ) )
    219223                $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
    220             $output = force_balance_tags($output);
     224            $output = force_balance_tags( $output );
    221225        }
    222 
    223     }
     226    }
     227
    224228    if ( $preview ) // preview fix for javascript bug with foreign languages
    225         $output =   preg_replace_callback('/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output);
     229        $output =   preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );
    226230
    227231    return $output;
Note: See TracChangeset for help on using the changeset viewer.