2011-12-15 78 views
0

有没有适当的方式来自动填充后缩略图?事实上,我问Vimeo-Api的视频缩略图。这项任务已经完成...WordPress的:自动填充后缩略图

但现在我需要添加收到的缩略图作为后缩略图。这样所有依赖的图像尺寸也会生成。

有什么建议吗?

回答

1

你可以试试这个(我没有测试这一点,但它应该工作,我用我的一个插件类似的东西):

  $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);