[wp-trac] [WordPress Trac] #12661: In TwentyTen Theme, use of Post Thumbnail in Content Area instead of as Header Replacement

WordPress Trac wp-trac at lists.automattic.com
Sun Mar 21 19:39:30 UTC 2010


#12661: In TwentyTen Theme, use of Post Thumbnail in Content Area instead of as
Header Replacement
--------------------------+-------------------------------------------------
 Reporter:  mikeschinkel  |       Owner:  iammattthomas
     Type:  defect (bug)  |      Status:  assigned     
 Priority:  normal        |   Milestone:  3.0          
Component:  Themes        |     Version:  3.0          
 Severity:  normal        |    Keywords:               
--------------------------+-------------------------------------------------
Changes (by mikeschinkel):

 * cc: mikeschinkel@… (added)


Comment:

 So as not to just ask and not provide code here is code I've written to
 insert into the content.  Aspects of it are not at all elegant (set how I
 used post meta for alignment and size) and it doesn't have anything to
 moderate the size of the image depending on context (i.e. it might be nice
 to have a different size in archives vs. post) but anywhere, here's some
 code:

 {{{
 add_action('the_content', 'insert_post_thumbnail_into_content');
 function insert_post_thumbnail_into_content($content) {
         global $post;
         $alignment = get_value(get_post_meta($post,'Post Thumbnail
 Alignment'),'alignright');
         $size = get_value(get_post_meta($post,'Post Thumbnail
 Size'),'full');
         $permalink = get_permalink($post);
         if (has_post_thumbnail( $post->ID )) {
                 $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
                 list($src,$width,$height) =
 wp_get_attachment_image_src($post_thumbnail_id, $size);
                 $post_thumbnail = get_post($post_thumbnail_id);
                 $img_link =<<<HTML
 <a href="$permalink">
 <img src="$src" alt="{$post_thumbnail->post_title}"
 title="{$post_thumbnail->post_title}"
 width="$width" height="$height" class="size-$size wp-
 image-$post_thumbnail_id" />'
 </a>
 HTML;
                 $caption = img_caption_shortcode(array(
                         'id'        => "attachment_$post_thumbnail_id",
                         'align'   => $alignment,
                         'width'   => $width,
                         'caption' => $post_thumbnail->post_excerpt,
                 ),$img_link);
         }
         return "$caption$content";
 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12661#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list