1

Request from a client. He wants his authors to be able to upload their image and then set it as featured, just like normal. The difference is that when setting it as featured, he wants the author to be able to choose 'small' or 'large' which will then be output appropriately on the front-end. How would you go about this? I'm well aware of how to create new image sizes in the theme, but how can I allow the author to select his image size when making his post?

2 Answers 2

2

You could add a meta box to the post add/edit screen below the featured image box to allow selection of size via a dropdown select menu. You could generate the list from available sizes (via get_intermediate_image_sizes), or just use your small/large strings. The data would be saved as post meta and you would simply get_post_meta() to get the selected size, then pass that result to the thumbnail function as the size parameter.

1
  • That is superb! I don't know why I didn't think of adding custom meta info to the posts. Thanks!
    – Kevin
    Commented May 22, 2013 at 0:30
1

You can alter the content of that meta box, which is unusual.

Proof of concept:

function alter_thumb_box($content, $postID) {
  return $content.'<input type="radio" name="thumb-size" value="" />';
}   
add_filter( 'admin_post_thumbnail_html', 'alter_thumb_box', 1, 2 );

You just need to add your fields and then provide a function to save the data, similar to function in the Codex examples.

1
  • 1
    This is great. Combining your answer with Milo's produced a very nice interface for selecting the image size. Much appreciated!
    – Kevin
    Commented May 22, 2013 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.