WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 years ago

#10928 closed task (blessed) (fixed)

Canonical Post Thumbnails

Reported by: markjaquith Owned by: markjaquith
Milestone: 2.9 Priority: high
Severity: normal Version:
Component: Post Thumbnails Keywords:
Focuses: Cc:

Description

Many themes and plugins use the concept of a post thumbnail — a representative image for the post. Generally, these are made by laboriously inserting a Custom Field with a full image URL.

WordPress would benefit from having an authoritative way of defining a post thumbnail that uses a GUI instead of custom fields, and specifies an image attachment ID instead of a URL so that themes may get that image in any size they want.

Attachments (9)

the_post_image_attr.diff (2.3 KB) - added by scribu 5 years ago.
Add $attr parameter to the_post_image()
remove_thumbnail.diff (4.0 KB) - added by scribu 5 years ago.
Add a "Remove Thumbnail" link
remove_thumbnail.2.diff (4.0 KB) - added by scribu 5 years ago.
Don't use global $post
referential_integrity.diff (728 bytes) - added by scribu 5 years ago.
page_thumbnails.php.diff (1.5 KB) - added by scribu 5 years ago.
revert_page_scripts.diff (844 bytes) - added by scribu 5 years ago.
use_as_thumbnail.diff (1.7 KB) - added by scribu 5 years ago.
use_as_thumbnail.2.diff (108.5 KB) - added by scribu 5 years ago.
fix_set_thumbnail_js.diff (3.5 KB) - added by scribu 5 years ago.

Download all attachments as: .zip

Change History (45)

comment:1 markjaquith5 years ago

(In [12007]) First pass on canonical post thumbanils. Admin-side GUI only. Theme functions to follow. see #10928

comment:2 chrisscott5 years ago

  • Cc chrisscott added

comment:3 markjaquith5 years ago

[12018] Add some filters, constrain image display in the admin.

comment:4 markjaquith5 years ago

(In [12019]) First pass at canonical post image template functions. see #10928

comment:5 markjaquith5 years ago

(In [12031]) Do not close media thickbox after thumbnail is selected, in case uploads are in progress. see #10928

comment:6 scribu5 years ago

There should be a way for the user to unset the thumbnail.

comment:7 scribu5 years ago

If you wanted to change the class attribute, this is what you'd have to write, with the current hooks:

add_action('begin_fetch_post_image_html', 'begin_post_image_hook');
add_action('end_fetch_post_image_html', 'end_post_image_hook');
function begin_post_image_hook() {
  add_filter('wp_get_attachment_image_attributes', 'post_image_hook');
}
function end_post_image_hook() {
  remove_filter('wp_get_attachment_image_attributes', 'post_image_hook');
}
function post_image_hook($attr) {
  $attr['class'] .= ' alignright';
	
  return $attr;
}

It works, but it's kind of verbose.

scribu5 years ago

Add $attr parameter to the_post_image()

scribu5 years ago

Add a "Remove Thumbnail" link

comment:8 markjaquith5 years ago

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

scribu5 years ago

Don't use global $post

comment:9 markjaquith5 years ago

(In [12036]) Post thumbnail removal functionality (only allowed for replacement before). props scribu. see #10928

comment:10 markjaquith5 years ago

(In [12037]) Remove close TB call that was removed earlier. see #10928

comment:11 markjaquith5 years ago

(In [12039]) Add wp-post-image CSS class to post images. see #10928

comment:12 scribu5 years ago

When deleting an attachment, all post thumbnails from that attachment should be cleared.

See referential_integrity.diff.

comment:13 markjaquith5 years ago

(In [12054]) Delete post thumbnail relationships for deleted attachments. props scribu. see #10928

scribu5 years ago

comment:14 scribu5 years ago

Pages could also use thumbnails. See page_thumbnails.php.diff

comment:15 markjaquith5 years ago

(In [12056]) Allow pages to have thumbnails too. Props scribu. see #10928

comment:16 markjaquith5 years ago

(In [12059]) Only show Use for thumbnail link for image attachments. see #10928

scribu5 years ago

comment:18 markjaquith5 years ago

(In [12064]) pull thumbnail scripts out of Page admin pages. see #10928. props scribu, gracious even in reversion.

comment:19 automattor5 years ago

(In [12065]) Pull thumbnail scripts out of Posts screens too. see #10928

comment:20 follow-up: navjotjsingh5 years ago

There are few problems I find in implementation of Post Thumbnails though. When you upload image, it only shows Insert into post at bottom which should also show Use for Thumbnail. So you will have to first upload image, browse to Media Library and then select Use for Thumbnails. Few clicks can be saved here.

And if a image has been selected as thumbnail and you go to media library second time, Use for Thumbnail is shown against that image too.

comment:21 in reply to: ↑ 20 scribu5 years ago

Replying to navjotjsingh:

There are few problems I find in implementation of Post Thumbnails though. When you upload image, it only shows Insert into post at bottom which should also show Use for Thumbnail. So you will have to first upload image, browse to Media Library and then select Use for Thumbnails. Few clicks can be saved here.

I agree that there should be a way to set a thumbnail without having to go to the Media Library tab.

And if a image has been selected as thumbnail and you go to media library second time, Use for Thumbnail is shown against that image too.

use_as_thumbnail.diff fixes this. Also does a little cleaning.

scribu5 years ago

scribu5 years ago

comment:22 scribu5 years ago

use_as_thumbnail.2.diff moves the "Use as thumbnail" link next to the "Insert into post" button.

comment:23 markjaquith5 years ago

use_as_thumbnail.2.diff removes the ability to set thumbnails from the post gallery.

comment:24 markjaquith5 years ago

Turns out that's not a regression, and this optimizes for the upload > set as thumbnail flow which I think will be more common.

comment:25 markjaquith5 years ago

(In [12081]) Save some clicks and optimize for the Upload, Set as thumbnail flow. props scribu. see #10928

comment:26 follow-up: navjotjsingh5 years ago

Can't say this patch [12081] will save clicks but now has increased one more click to set as thumbnail. Now the Use as Thumbnail appears only when you click Show in Media Library against the Image and that too as a link instead of a nice button? Only the second problem appears to have been fixed from my last post.

And why does Use as Thumbnail changes to Use for Thumbnail on setting a thumbnail? Link should disappear when it gets set as Thumbnail.

comment:27 in reply to: ↑ 26 scribu5 years ago

Replying to navjotjsingh:

Can't say this patch [12081] will save clicks but now has increased one more click to set as thumbnail. Now the Use as Thumbnail appears only when you click Show in Media Library against the Image and that too as a link instead of a nice button? Only the second problem appears to have been fixed from my last post.

Not all clicks are created equal: the previous click involved loading a new tab, which is much slower than expanding a media item. The flow will probably be improved with the new Media UI in a future release.

And why does Use as Thumbnail changes to Use for Thumbnail on setting a thumbnail? Link should disappear when it gets set as Thumbnail.

Yes, this should be fixed.

comment:28 scribu5 years ago

Related: #10992.

scribu5 years ago

comment:29 automattor4 years ago

(In [12111]) thumbnail JS fixes. props scribu. see #10928

comment:30 automattor4 years ago

(In [12134]) Introduce require_if_theme_supports(), move post thumbnails functions to there own include and only included them if the theme supports them. See #10928 and [12132]

comment:32 scribu4 years ago

related: #11196

comment:33 ryan4 years ago

  • Component changed from Media to Post Thumbnails

comment:34 ryan4 years ago

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

comment:35 aaroncampbell4 years ago

  • Cc aaron@… added
  • Resolution fixed deleted
  • Status changed from closed to reopened

It would be really nice if a plugin could enable support of this as well. For example, I want http://wordpress.org/extend/plugins/featured-content-showcase/ to be able to enable the functionality so I don't have to tell the user to add a line to their theme's functions.php file during installation, but the require_if_theme_supports() call in wp-settings happens too early.

If this should be a different ticket, let me know and I'll open one.

comment:36 aaroncampbell4 years ago

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

Sorry, this was my mistake. I moved the command to the plugin and at the same time updated it to use post-images. The site's only on the newest nightly though, so it was still checking post-thumbnails.

Note: See TracTickets for help on using tickets.