Allow theme devs to change attrs (like CSS class) of thumbnail images. props scribu. see #10928

git-svn-id: https://develop.svn.wordpress.org/trunk@12035 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Mark Jaquith 2009-10-15 12:31:48 +00:00
parent da87e95962
commit 45b4ea5807
2 changed files with 8 additions and 7 deletions

View File

@ -527,7 +527,7 @@ function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon =
* @param bool $icon Optional, default is false. Whether it is an icon.
* @return string HTML img element or empty string on failure.
*/
function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false) {
function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') {
$html = '';
$image = wp_get_attachment_image_src($attachment_id, $size, $icon);
@ -537,12 +537,13 @@ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa
if ( is_array($size) )
$size = join('x', $size);
$attachment =& get_post($attachment_id);
$attr = array(
$default_attr = array(
'src' => $src,
'class' => "attachment-$size",
'alt' => trim(strip_tags( $attachment->post_excerpt )),
'title' => trim(strip_tags( $attachment->post_title )),
);
);
$attr = wp_parse_args($attr, $default_attr);
$attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment );
$attr = array_map( 'esc_attr', $attr );
$html = rtrim("<img $hwstring");

View File

@ -909,18 +909,18 @@ function get_post_image_id( $post_id = NULL ) {
return get_post_meta( $post_id, '_thumbnail_id', true );
}
function the_post_image( $size = 'thumbnail' ) {
echo get_the_post_image( $size );
function the_post_image( $size = 'thumbnail', $attr = '' ) {
echo get_the_post_image( NULL, $size, $attr );
}
function get_the_post_image( $size = 'thumbnail', $post_id = NULL ) {
function get_the_post_image( $post_id = NULL, $size = 'thumbnail', $attr = '' ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
$post_image_id = get_post_image_id( $post_id );
$size = apply_filters( 'post_image_size', $size );
if ( $post_image_id ) {
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
$html = wp_get_attachment_image( $post_image_id, $size );
$html = wp_get_attachment_image( $post_image_id, $size, false, $attr );
do_action( 'end_fetch_post_image_html', $post_id, $post_image_id, $size );
} else {
$html = '';