2014-06-05 22 views
0

我一直在尋找這一點,並沒有發現任何與此相關的任何內容。Wordpress自定義上傳器沒有顯示附件設置

我在插件中使用自定義上傳器來插入圖像。

我使用的代碼是這樣的

$('#upload_image_button').click(function(e) { 
    e.preventDefault(); 
    //If the uploader object has already been created, reopen the dialog 
    if (custom_uploader) { 
     custom_uploader.open(); 
     return; 
    } 
    //Extend the wp.media object 
    custom_uploader = wp.media.frames.file_frame = wp.media({ 
     title: 'Choose Image', 
     button: { 
      text: 'Choose Image' 
     }, 
     multiple: false 
    }); 
    //When a file is selected, grab the URL and set it as the text field's value 
    custom_uploader.on('select', function() { 
     attachment = custom_uploader.state().get('selection').first().toJSON(); 
     console.log(attachment); 
     $('.ppwfg-images td').append("<div id='image-placeholders' style='width:75px; height:75px; margin: 3px; float: left;'>"); 
     $('#image-placeholders').append("<input type='text' id='upload_image' name='ppwfg[]' class='' value='' size='10' hidden />"); 
     $('#image-placeholders').append("<img src='' id='upload_image_holder' class='ppwfg_image' style='width:75px; height:75px; margin: 3px;'/>"); 
     $('#image-placeholders').append("<a class='close-overlay remove'>x</a>"); 

     $('#image-placeholders').attr("id", attachment.id); 

     $('#upload_image').attr("value", attachment.url); 
     $('#upload_image').attr("class", attachment.id); 
     $('#upload_image').attr("id", attachment.id); 

     $('#upload_image_holder').attr("src", attachment.url); 
     $('#upload_image_holder').attr("class", attachment.id); 
     $('#upload_image_holder').attr("id", attachment.id); 
    }); 
    //Open the uploader dialog 
    custom_uploader.open(); 
}); 

的上傳開,我可以選擇圖像,然後插入它,但問題是,它總是使用主圖像,並沒有顯示出與附件設置下拉選擇要使用的圖像...所以我剩下的是默認圖像,最終會變成大圖。

如何顯示media.frame中的附件設置?

回答

0

太舊了,但認爲我會回答一些仍在尋找的人。

custom_uploader = wp.media.frames.file_frame = wp.media({ 
     title: 'Choose Image', 
     button: { 
      text: 'Choose Image' 
     }, 
     frame: 'post', 
     state: 'insert', 
     multiple: false 
    }); 

    //When a file is selected, grab the URL and set it as the text field's value 
    custom_uploader.on('insert', function() { 

您可以選擇框架:職位,但那麼你已經選擇狀態:插入和使用功能custom_uploader.on(「插入」,函數(){

相關問題