in WordPress, Wordpress Plugin, Wordpress Themes

How to use timthumb in WP MU

I think to show the first image as thumb in wp front page or blog layout is very common for any theme. But to use it in wordpress mu version is not direct or need to do some hack or modify the normall process of adding timthub. Normally we upload images from wp media manager and use those in posts. In normal wordpress the upload dir is wp-content/uploads and files and images are uploaded to that directory. In wordpress mu version files are uploaded by user basis folder and for this wp-content/blogs.dir/userid is the uploaded dir for any image. here user id is named as folder name for each user. then wp-content/blogs.dir/userid/files. But when u browse the site the image link format is like http://yoursitename/files/year/month/image name but format is reshaped by the wp mu htacces which real physical path is like wp-content/blogs.dir/userid/files/year/month/image name.

the common way to get the first image link from a wp post to use this for timthumb is like bellow:
in wp loop
[code language=”php”]
$pattern = ‘!preg_match_all($pattern, $post->post_content, $matches);$image_src = $matches[‘1’][0];
[/code]
if $image_src is not null then we generally use this src for image to be used as image src for timthumb. But for wp mu this will not work as for wp mu the physical path is diff.

Sol: Use global var $blog_id like global $wpdb,$post,$blog_id;
and then
[code language=”php”]
if($image_src != ”)
{
$replace = ‘wp-content/blogs.dir/’.$blog_id.’/files’;$image_src = str_replace(‘files’,$replace,$image_src);

}
[/code]
hope u know how to use timthumb and will get solution for using it in wp mu. may this post will remove some pain when u are here by google search about this problem
thanks

  1. SO where do you paste these codes to make it work??

    Sorry, Im not very familiar with codes

Comments are closed.