是否有合适的方式自动填充后缩略图?事实上,我向Vimeo-Api要了一个视频缩略图。此任务已完成...
但现在我需要将接收到的缩略图添加为Post-Thumbnail。这样也会生成所有相关的图像大小。
有什么建议吗?
发布于 2011-12-15 19:03:42
你可以试试这个(我没有测试它,但它应该可以工作,我在我的一个插件中使用了类似的东西):
$image_path = 'path to your image';
$id = 'id of corresponding post';
$title = 'title of your image';
// Checking the filetype
$wp_filetype = wp_check_filetype(basename($image_path), null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => $title,
'post_content' => '',
'post_status' => 'inherit',
'post_parent' => $id
);
// inserting the attachment
$attach_id=wp_insert_attachment($attachment,$image_path);
require_once(ABSPATH . 'wp-admin/includes/image.php');
// Generating the metadate (and the thumbnails)
$attach_data=wp_generate_attachment_metadata($attach_id,$image_path );
// Setting it as thumbnail
update_post_meta( $id, '_thumbnail_id', $attach_id );https://stackoverflow.com/questions/8518863
复制相似问题