如果您查看原始post数据。。。
while (have_posts() ) {
the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>><?php
var_dump($post); ?>
</article><?php
}
你会看到里面没有什么可以指定“中等”,所以我去看了看。
There is a filter on the_content
... add_filter( \'the_content\', \'prepend_attachment\' );
。。。那个
juggles data for "attachment" post types.
1576 function prepend_attachment($content) {
1577 $post = get_post();
1578
1579 if ( empty($post->post_type) || $post->post_type != \'attachment\' )
1580 return $content;
1581
1582 if ( wp_attachment_is( \'video\', $post ) ) {
1583 $meta = wp_get_attachment_metadata( get_the_ID() );
1584 $atts = array( \'src\' => wp_get_attachment_url() );
1585 if ( ! empty( $meta[\'width\'] ) && ! empty( $meta[\'height\'] ) ) {
1586 $atts[\'width\'] = (int) $meta[\'width\'];
1587 $atts[\'height\'] = (int) $meta[\'height\'];
1588 }
1589 if ( has_post_thumbnail() ) {
1590 $atts[\'poster\'] = wp_get_attachment_url( get_post_thumbnail_id() );
1591 }
1592 $p = wp_video_shortcode( $atts );
1593 } elseif ( wp_attachment_is( \'audio\', $post ) ) {
1594 $p = wp_audio_shortcode( array( \'src\' => wp_get_attachment_url() ) );
1595 } else {
1596 $p = \'<p class="attachment">\';
1597 // show the medium sized image representation of the attachment if available, and link to the raw file
1598 $p .= wp_get_attachment_link(0, \'medium\', false);
1599 $p .= \'</p>\';
1600 }
1601
1602 /**
1603 * Filter the attachment markup to be prepended to the post content.
1604 *
1605 * @since 2.0.0
1606 *
1607 * @see prepend_attachment()
1608 *
1609 * @param string $p The attachment HTML output.
1610 */
1611 $p = apply_filters( \'prepend_attachment\', $p );
1612
1613 return "$p\\n$content";
1614 }
相关行为1597和1598。
wp_get_attachment_link()
, 反过来使用
wp_get_attachment_image()
(第1545行),其中使用
image_downsize()
... 还有一个很有前途的过滤器:
167 if ( $out = apply_filters( \'image_downsize\', false, $id, $size ) ) {
168 return $out;
169 }
等一下中提琴
function image_size_hack() {
$img_url = wp_get_attachment_url();
$meta = wp_get_attachment_metadata();
$width= $height = \'\';
if (!empty($meta[\'width\'])) {
$width = $meta[\'width\'];
}
if (!empty($meta[\'height\'])) {
$width = $meta[\'height\'];
}
return array( $img_url, $width, $height, false );
}
add_filter( \'image_downsize\', \'image_size_hack\');