Ticket #10928: the_post_image_attr.diff
File the_post_image_attr.diff, 2.3 KB (added by , 15 years ago) |
---|
-
post-template.php
909 909 return get_post_meta( $post_id, '_thumbnail_id', true ); 910 910 } 911 911 912 function the_post_image( $size = 'thumbnail' ) {913 echo get_the_post_image( $size);912 function the_post_image( $size = 'thumbnail', $attr = '' ) { 913 echo get_the_post_image($size, $attr); 914 914 } 915 915 916 function get_the_post_image( $size = 'thumbnail', $ post_id = NULL ) {916 function get_the_post_image( $size = 'thumbnail', $attr = '', $post_id = NULL ) { 917 917 global $id; 918 918 $post_id = ( NULL === $post_id ) ? $id : $post_id; 919 919 $post_image_id = get_post_image_id( $post_id ); 920 920 $size = apply_filters( 'post_image_size', $size ); 921 921 if ( $post_image_id ) { 922 922 do_action( 'begin_fetch_post_image_html', $post_id, $post_image_id, $size ); // for "Just In Time" filtering of all of wp_get_attachment_image()'s filters 923 $html = wp_get_attachment_image( $post_image_id, $size );923 $html = wp_get_attachment_image( $post_image_id, $size, false, $attr ); 924 924 do_action( 'end_fetch_post_image_html', $post_id, $post_image_id, $size ); 925 925 } else { 926 926 $html = ''; -
media.php
527 527 * @param bool $icon Optional, default is false. Whether it is an icon. 528 528 * @return string HTML img element or empty string on failure. 529 529 */ 530 function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false ) {530 function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') { 531 531 532 532 $html = ''; 533 533 $image = wp_get_attachment_image_src($attachment_id, $size, $icon); … … 537 537 if ( is_array($size) ) 538 538 $size = join('x', $size); 539 539 $attachment =& get_post($attachment_id); 540 $ attr = array(540 $default_attr = array( 541 541 'src' => $src, 542 542 'class' => "attachment-$size", 543 543 'alt' => trim(strip_tags( $attachment->post_excerpt )), 544 544 'title' => trim(strip_tags( $attachment->post_title )), 545 ); 545 ); 546 $attr = wp_parse_args($attr, $default_attr); 546 547 $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment ); 547 548 $attr = array_map( 'esc_attr', $attr ); 548 549 $html = rtrim("<img $hwstring");