2011-12-15 5 views
0

자동으로 미리보기 이미지를 채울 적절한 방법이 있습니까? 사실 Vimeo-Api에 Video-Thumbnail을 요청합니다. 이 작업은 이미 완료되었습니다 ...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); 
관련 문제