1
我在我的WP網站的帖子,我用這個代碼來獲取縮略圖的網址:如何獲得一個職位縮略圖與WP卸載S3 WordPress插件
$thumb_id = get_post_thumbnail_id($single->ID);
$thumb_url = get_guid($thumb_id);
我已經安裝了WP卸載S3插件,但我的代碼返回了本地文件url而不是S3 url。
你能幫助我嗎?
我在我的WP網站的帖子,我用這個代碼來獲取縮略圖的網址:如何獲得一個職位縮略圖與WP卸載S3 WordPress插件
$thumb_id = get_post_thumbnail_id($single->ID);
$thumb_url = get_guid($thumb_id);
我已經安裝了WP卸載S3插件,但我的代碼返回了本地文件url而不是S3 url。
你能幫助我嗎?
我終於找到了在數據庫中搜索的方法。我發現在postmeta表,「amazonS3_info」數據,與我需要生成文件的URL中的所有相關信息:
function get_s3_thumb($post_id){
$thum_id = get_post_thumbnail_id($post_id);
$meta = get_post_meta($thum_id, 'amazonS3_info');
if(count($meta)){
// The file exist in S3
$meta = $meta[0];
$url = ($_SERVER['HTTPS'] == 'on')?'https':'http';
$url.= '://s3-';
$url.= $meta['region'];
$url.= '.amazonaws.com/';
$url.= $meta['bucket'];
$url.= '/';
$url.= $meta['key'];
}else{
// The file dosen't exist in S3
$url = get_guid($thum_id);
if($_SERVER['HTTPS'] == 'on'){
$url = str_replace('http', 'https', $url);
}
}
return $url;
}
我後我的功能,如果有人需要它的一天。
您是否嘗試過插件的支持論壇? – Random