2011-12-15 74 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);