篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP Wordpress MU timthumb修复相关的知识,希望对你有一定的参考价值。
/*
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);
preg_match ('/src="(.*)" class/',$thumbnail_id,$link);
$imageParts = explode('files/', $link[1]);
if (!empty($imageParts[1])):
//check if the image is in the blog directory
if(@getimagesize('./wp-content/blogs.dir/' . $blog_id . '/files/' . $imageParts[1])):
$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)
if(@getimagesize('./wp-content/uploads/' . $imageParts[1])):
$thumbnail = 'http://'.$_SERVER['HTTP_HOST'].'/wp-content/uploads/' . $imageParts[1];
endif;
else:
$imageParts = explode('uploads/', $link[1]);
if(@getimagesize('./wp-content/uploads/' . $imageParts[1])):
$thumbnail = 'http://'.$_SERVER['HTTP_HOST'].'/wp-content/uploads/' . $imageParts[1];
endif;
endif;
else:
$thumbnail_id=get_the_post_thumbnail($post_id);
preg_match ('/src="(.*)" class/',$thumbnail_id,$link);
$thumbnail = $link[1];
endif;
return $thumbnail;
}
以上是关于PHP Wordpress MU timthumb修复的主要内容,如果未能解决你的问题,请参考以下文章