Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#12661 closed defect (bug) (fixed)

In TwentyTen Theme, use of Post Thumbnail in Content Area instead of as Header Replacement

Reported by: mikeschinkel's profile mikeschinkel Owned by: iammattthomas's profile iammattthomas
Milestone: 3.0 Priority: normal
Severity: normal Version: 3.0
Component: Themes Keywords:
Focuses: Cc:

Description

I just spent 1/2 hour with an end user trying to figure out why the site got all whacked out when a post thumbnail was assigned using the Twenty Ten theme. She was very confused because it appeared to her that the header disappeared and the thumbnail was forced up to the top left corner. After diving into the code I realized it was by design!

Please reconsider this. I'm pretty sure most people (myself included) would think the post thumbnail would show up in the content area, not in the header. Not doing so simply leads to confusion, especially for less skilled users and I think that is completely counter to WordPress' philosophy and definitely something those of us who deal with end users will have to repeatedly make excuses for WordPress doing (i.e. like my end user who said to me "Why the heck would it do that?!?! That's brain-dead!!'')

And if for some strange reason someone is in love with this behavior please make it an option in theme settings, and make replacing the header not the default option.

(BTW, my end user is working with me to enter data on a site of my own where I'm using WP3.0 and TwentyTen, this is not a client project.)

Change History (12)

#1 @nacin
14 years ago

  • Milestone changed from Unassigned to 3.0
  • Owner set to iammattthomas
  • Status changed from new to assigned

Assigning to Matt for review.

#2 @mikeschinkel
14 years ago

  • Cc mikeschinkel@… added

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";
}

#3 @mikeschinkel
14 years ago

Oops, used a helper function which I didn't include. Here it is:

function get_value($value,$default) {
	if (is_null($value) || empty($value))
		return $default;
	else
		return $value;
}

#4 @iammattthomas
14 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In r13836, twentyten now ignores the post thumbnail unless it's sized to fit the header image space.

#5 @nacin
14 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

#6 @nacin
14 years ago

Looks like this causes some issues on a page that isn't singular, as we're unconditionally checking for $post->ID, which wouldn't always be a post object (like on a 404).

Additionally, is_singular() includes attachments. We may want that to only be is_singular() && !is_attachment() (or I guess that would be is_single()
is_page()).

Untested, but something like this should do the trick:

<?php
// Retrieve the dimensions of the current post thumbnail -- no teensy header images for us!
// Check if this is a post or page, if it has a thumbnail, and if it's a big one
if ( is_singular() && has_post_thumbnail() && $image = wp_get_attachment_image_src( get_post_thumbnail_id() ) && $image['width'] >= HEADER_IMAGE_WIDTH ) :
	the_post_thumbnail();
else : ?>
				<img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
<?php endif; ?>

#7 @dd32
14 years ago

Looks like this causes some issues on a page that isn't singular, as we're unconditionally checking for $post->ID, which wouldn't always be a post object (like on a 404).

Yeah, 404 pages trigger it pretty well. I used something similar in a child theme yesterday to what you've got there.

is_singular() is fine, as Attachments do not have Featured Images by default.

#8 @nacin
14 years ago

is_singular() is fine, as Attachments do not have Featured Images by default.

Ah, true.

#9 @dd32
14 years ago

				<?php
					// Check if this is a post or page, if it has a thumbnail, and if it's a big one
					if ( is_singular() && has_post_thumbnail( $post->ID ) && ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail')) && $image[1] >= HEADER_IMAGE_WIDTH ) :		
						// Houston, we have a new header image!
						echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
					else : ?>
						<img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
					<?php endif; ?>

#10 @nacin
14 years ago

Good catch. We should probably have wp_get_attachment_image_src also return associative keys though.

#11 @dd32
14 years ago

We should probably have wp_get_attachment_image_src also return associative keys though.

Would be nice in some locations, But i'm not willing to go hunting through the media related functions right now making sure they all return consistant results (That function can return data from 3 locations i believe, and thats not taking into account older uploads).

#12 @dd32
14 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [14002]) Move all Feature Images => header image integration into a is_singular() check. Prevents a PHP notice when $post is not set (For example, a 404 page). Fixes #12661

Note: See TracTickets for help on using tickets.