我有12,000个帖子,我需要为其生成缩略图。图像已经在“上传”文件夹中。问题在于,即使那样,过程仍然非常缓慢。此功能花费的时间太长。我可以做些什么来使其更快?
function Generate_Featured_Image( $code_url, $post_id, $video_id){
$upload_dir = wp_upload_dir();
$path = $upload_dir['basedir'] . "/save/{$video_id}/";
for($i = 6; $i >= 1; $i-- ){
$filename = $i.'.jpg';
if(wp_mkdir_p($path)) $file = $upload_dir['basedir'] . "/save/{$video_id}/" . $filename;
}
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name($filename),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $file, $post_id );
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
$res1= wp_update_attachment_metadata( $attach_id, $attach_data );
$res2= set_post_thumbnail( $post_id, $attach_id );
}
答案 0 :(得分:-1)
您有一个缓存插件和一个延迟加载插件吗?如果您安装jetpack(免费),则将有一个免费的CDN。 所以要点是: 1-如果没有安装缓存插件 2-如果没有安装延迟加载 3-如果没有安装jetpack(免费),则可以免费获得CDN
CDN可以加快网站访问速度