Tag Archives: thumbnails

WordPress Post Thumbnails: Migrating from Custom Fields to the Featured Image API

I had post thumbnails on this blog a long time before the feature became a part of the WordPress core. Some of you out there may have, too. The technique that was generally used before the friendly “Featured Image” box, and its associated theme API, was added to WordPress, we generally just pasting image URLs into custom fields and outputted them into an image tag in the theme. Basically, like I recommended in this old post from 2008.

When WordPress 2.9 was released, bringing with it an “official” way to handle thumbnails, I was a little bit annoyed. I had tons of posts where I had existing thumbnails that would have to be somehow updated, or else I would have to come up with some clever way to be backwards-compatible. So I just put it out of my mind and left things the way they were…until this year.

Redesigning gave me an excuse to modernize a lot of the stuff going on behind-the-scenes, and one of the things I improved was the handling of post thumbnails. The solution was easy: write a function to handle two methods of applying a thumbnail, and check both places for a thumbnail. The code looks something like this:

Continue reading →

WordPress 2.9 has Thumbnail Support. What Does This Mean for Existing Themes?

When WordPress 2.9 came out, one of the touted features was the “official” support for post thumbnails. Instead of storing URLs in custom fields, a new method with an easy UI was added. This is great for one major reason: now your thumbnails are less reliant on your theme. If you change your theme, you don’t have to worry about editing it to use the same custom field as your previous theme. Plugins, also, can now easily retrieve post thumbnails, as they don’t have to guess at your custom field.

Unfortunately, this new feature raises a new problem. What if you already have an existing, custom field-based, thumbnail solution? How can you easily (and optimally) move from one to the other?

I have another blog running a plugin called Wordbooker. It automatically syndicates links to my posts on Facebook. It can include the posts’ thumbnails when it does so, but it relies on WP 2.9’s way of doing things. Facebook “fans” won’t see the nice images by the links unless I were to migrate from custom fields to the new built-in thumbnail feature. How do I do that?

I could update my template to use PHP “if” statements to determine which method it should use for each post, and just use the new thumbnails for new post. That seems a little clunky though. Another, cleaner, option would be to have a look at the SQL columns and build a query to create the new thumbnails.

This seems like a great opportunity for a plugin developer. A single-use “importer” that reads an inputted custom field and iterates through all of your posts, creating the new thumbnail entries.

Automated Website Thumbnails via WordPress.com

Ben Gillbanks has unearthed a neat, undocumented API. If you have a look at his WPVote site, you’ll note that next to each link there is a thumbnail or the originating site.

There are several services that can generate thumbnails like that, but most of them place watermarks on the images or place limits on how many API calls you can make in a month. (Amazon used to offer a paid service, but it was discontinued a year or two ago.)

To my surprise, when I was submitting an article to WPVote recently, I found that the thumbnails were served up by a subdomain of WordPress.com. I thought something along the lines of “Eh? I didn’t know they offered a screenshot service…” and continued about my business.

A couple days later, I spotted Ben’s blog post in my feed reader. In it he explained how he discovered a dynamic URL that Automattic uses, in places like the WordPress.org commercial themes page, to display thumbnails. He posted an email to Matt Mullenweg about it and got this as a response:

You can use it and link to it, but it’s not official. It’s not worth the effort to try to make it into a business – we have to support it anyway for our own apps.

Sounds good to me. :) Obviously it wouldn’t be nice to use it for something huge and high-traffic, but it seems like they don’t object to us smaller WordPress fanatics making use of it.

http://s.wordpress.com/mshots/v1/http%3A%2F%2Fprothemedesign.com%2F?w=250

There’s now a WordPress plugin that makes it easy to use the thumbnails in blog posts, with a shortcode, or elsewhere with a template tag.

Automattic WordPress Post Thumbnails

There are plenty of posts floating around the internet about using Custom Fields to assign thumbnail images to individual posts in WordPress. Web Developer Plus has a different idea.

Do you often put images in your posts? You probably upload them through the media manager built right in to the WordPress post editor. Every time you upload an image, it’s associated with the post you first attach it to. And WordPress creates a thumbnail to go along with it, of the size specified in the media settings.

Web Developer Plus has a an article on how to automatically find the thumbnail URL of the first image attached to a post and store it in the variable $img, which you can then echo out into an <img /> tag wherever you want the thumbnail to appear.

Continue reading →