2011-11-28 21 views
0

我堅持了這個問題超過8小時。我爲我的wordpress主題創建了一個選項面板,併爲上傳徽標選項添加了上傳按鈕。我正在使用wordpress thickbox。除了thickbox上傳之外,幾乎完成的任何事情都不會只顯示正在顯示的thickbox疊加層。我檢查了源文件,並且.js文件和樣式表文件被正確註冊了入隊。爲什麼thickbox不顯示?請幫幫我!爲什麼wordpress thickbox沒有真正顯示我的主題上傳選項

這裏是我的腳本通過使用輸入按鈕來調用ThickBox的

var fileInput = ''; 

    jQuery('.upload_image_button').click(function() { 
     fileInput = jQuery(this).parent().prev('input.uploadfield'); 
     //console.log(fileInput); 
     formfield = jQuery('#upload_image').attr('name'); 
     post_id = jQuery('#post_ID').val(); 
     tb_show('', 'media-upload.php?post_id='+post_id+'&type=image&TB_iframe=true&width=640&height=105'); 
     return false; 
    }); 



    window.original_send_to_editor = window.send_to_editor; 
    window.send_to_editor = function(html){ 

     if (fileInput) { 
      fileurl = jQuery('img',html).attr('src'); 

      fileInput.val(fileurl); 

      tb_remove(); 

     } else { 
      window.original_send_to_editor(html); 
     } 
    }; 

,這裏是上傳

<input id="" class="uploadfield" type="text" value="" name="" size="50" maxlength="2048"> 
              <div class="upload_buttons"> 
               <input class="upload_image_button" type="button" value="Upload"> 
              </div> 
+0

我試圖用螢火蟲調試腳本。我得到的是TB_window div甚至沒有任何內容。就像這樣

。但我仍然不知道如何解決這個問題。 – nonsensecreativity

+0

已解決!這是因爲我從ajax googleapis註冊了jquery 1.4.2。爲了解決這個問題,我下載了最新的jQuery,然後我註冊並將腳本排入新的admin_jquery。它工作正常。我只是不知道爲什麼它不適用於Ajax googleapis的jquery。 – nonsensecreativity

+0

:發佈您的解決方案作爲答案。這可能有助於其他人 – Gowri

回答

0

我發現真正的問題我輸入按鈕的代碼,因爲我在我的jquery文件中使用jQuery()而不是$我的代碼與在jquery中構建的wordpress發生衝突。所以我必須註冊新的jQuery與相同的名稱'jquery',而不註銷jQuery中的wordpress構建。

我改變了標誌,然後我可以使用jquery中的wordpress構建,而無需註冊新的jquery和thickbox正常工作。希望這可以幫助有同樣問題的人。謝謝

+0

當我想我註冊新的jQuery腳本解決了問題時,我第一次非常笨拙。 :(但這是錯誤的方法,即使它修復了thickbox,但它的行爲很奇怪,當彈出時thickbox本身有2個關閉按鈕 – nonsensecreativity

+0

不,你沒有笨拙我已經測試了你的js代碼,它工作正常: WordPress的本地MediaUpload顯示正確(我從'tb_show'中刪除post_id)。這就是我在生成選項頁的函數中插入所需腳本的方式:'wp_register_script('yourjs',get_template_directory_uri()。'/js/your.js '';'wp_enqueue_script('yourjs');''wp_enqueue_script('media-upload');''wp_enqueue_script('thickbox');''wp_enqueue_script('thickbox');'' 'wp_enqueue_style('thickbox');'你不需要添加jQuery,因爲它已經包含了(參見'wp-includes/script-loader.php')。 – jocki

相關問題