/ Published in: PHP
This function will return the correct url for the timthumb php script (wordpress 3.0 or higher required!)
Usage: just call the function in your theme with the post id as parameter, it will return a value so store this into a variable (must be inside the wordpress loop to work)
The function:
$thumb = get_timthumb_thumbnail($post->ID);
I've tested this successfully on my servers so please let me know if you are having any problem with it.
Usage: just call the function in your theme with the post id as parameter, it will return a value so store this into a variable (must be inside the wordpress loop to work)
The function:
$thumb = get_timthumb_thumbnail($post->ID);
I've tested this successfully on my servers so please let me know if you are having any problem with it.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* WORDPRESS MU TIMTHUMB FIX This function will return the correct url for the timthumb php script (wordpress 3.0 or higher required!) Usage: just call the function in your theme with the post id as parameter, it will return a value so store this into a variable (must be inside the wordpress loop to work) The function: $thumb = get_timthumb_thumbnail($post->ID); */ function get_timthumb_thumbnail($post_id = null) { global $blog_id; //we can access it, so why not use it? $is_mu = WP_ALLOW_MULTISITE; //if is true it means it's a wordpress MU site and we'll have to do some work if($is_mu == true): $thumbnail_id=get_the_post_thumbnail($post_id); //check if the image is in the blog directory $thumbnail = 'http://'.$_SERVER['HTTP_HOST'].'/wp-content/blogs.dir/' . $blog_id . '/files/' . $imageParts[1]; endif; //check if the image is in the main uploads directory (you never know) $thumbnail = 'http://'.$_SERVER['HTTP_HOST'].'/wp-content/uploads/' . $imageParts[1]; endif; else: $thumbnail = 'http://'.$_SERVER['HTTP_HOST'].'/wp-content/uploads/' . $imageParts[1]; endif; endif; else: $thumbnail_id=get_the_post_thumbnail($post_id); $thumbnail = $link[1]; endif; return $thumbnail; }