WPMU media locations
WPMU implements a URL rewrite for uploaded media so that the location of an uploaded file is given as
http://www.example.com/files/2009/01/image.jpg, but the actual URL of the file is
http://www.example.com/wp-content/blogs.dir/BLOG_ID/files/2009/01/image.jpg (where BLOG_ID is the ID of the blog in question).
The easiest way to specify the URL for a post image (whether you’re using Thesis post images, or custom fields to add a post thumbnail, or something else) is to copy the URL that WordPress inserts into the post. However, this URL doesn’t work with the TimThumb script (which Thesis and other themes use to generate thumbnails from larger images). Essentially TimThumb looks for the image file at the URL you specify, but the image file doesn’t exist there and the redirect that allows you to see the image in the browser doesn’t work for the script.
Overcoming the TimThumb problem
There’s two ways that I can see to get TimThumb working on your site: modify your behaviour, or modify the script’s behaviour.
Modify your behaviour
You could simply edit the URL that you copy from WordPress and add
wp-content/blogs.dir/BLOG_ID/ into the image URL you want to use.
I don’t like this because it won’t fix any posts that have already been written and it’s extra work for the user every time they write a post. It also might not be easy for some users to remember that they need to change the URL, or in what way they need to change it.
Modify TimThumb’s behaviour
I came across a TimThumb hack for Thesis, but it didn’t work for me at all. I suspect it had something to do with my image URLs not being relative, but I’m not sure.
I was able to use the first part of the information in that post to make the blog IDs available in the TimThumb script and then using PHP replace the
/files/ part of the URL with
In the Thesis theme (version 1.7 at the time of writing) the TimThumb script is located at thesis_17/lib/scripts/thumb.php.
Update 5th Nov 2010: Changed line 448 below to fix a problem with this on blogs within a site network. Also, these edits still work the same with Thesis 1.8.
- At line 23 (after the end of the file comments section) I added
to make the blog IDs available.
- After line 447, which says
$src = preg_replace("/\.\.+\//", "", $src);
To line 448 (initially an empty line) I added
global $current_site; global $current_blog; $src = str_replace($current_blog->path.'files/', $current_site->path.'wp-content/blogs.dir/'.$current_blog->blog_id.'/files/', $src);
to replace the section of the image URL we need to change.
Other themes may use their own version of the TimThumb script, or they might use the one included with WPMU. These modifications should work with them, but the line numbers might be slightly different.
In theory this modification could be present in regular WordPress installations and in WordPress 3.0 with networks turned on or off (assuming WP3.0 directory structure is the same) without affecting the existing behaviour of the script. If “/files/” is not found in the image URL, it won’t be replaced and the image URL will remain the same.
In the long run it might be better to use the thumbnails built into WordPress. However, the caveat there is you will need to regenerate the different image sizes after setting up theme support for thumbnails, whereas TimThumb generates thumbnails on the fly and then caches them: changing image sizes is not a big deal with TimThumb.