2015-09-05 103 views
0

在Wordpres中,我創建了一個插件。我試圖使用Bootstrap/bootstrap-select來創建自定義頁面模板上的多選(帶有複選框),但是我遇到了問題。我沒有創建新的主題,但我正在使用兒童主題。這裏是我做了什麼:

  1. 從父主題給孩子

    複製page.php文件並重新命名它來管理,matches.php

  2. 編輯模板,並添加

    • 模板名稱:管理比賽
  3. 創建一個新的頁面,並選擇了這個新的模板
  4. 在模板循環內容的div,我調用另一個PHP文件中使用: 此功能在managematches.php,我已經
  5. 我複製我的header.php孩子並添加到bootstrap.css引用和bootstrap-select.css
  6. 我已經完成 include_once'includes/managematches.php'; 在我的插件。

這個函數managematches()生成我的頁面的html,它工作正常。實際上,我可以創建bootstrap元素,所以我知道bootstrap/bootstrap-select.css文件正在工作。我還創建了一個.js文件(managematches.js)並將其排入隊列,並且正在運行。通過工作,我的意思是標準的jQuery函數和選擇器工作正常。

問題是我無法獲得bootstrap-select.js中的任何函數來工作。我試着把它的參考文件放在一大堆地方,無濟於事。我不斷收到:

TypeError: $(...).selectpicker is not a function 

的問題說明如下:Bootstrap-select not working ,我知道我的問題是,我需要確保自舉select.js加載我的代碼之前包括在內。

我不清楚的是如何在wordpress環境中做到這一點。我很接近,但不是我想成爲的地方。如果任何人有關於如何解決這個問題的建議,我將不勝感激。

ANSWER 我入隊,我插件CSS和JS,但functions.php的將工作太。

wp_enqueue_style('bootstrap', 'http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'); 

wp_enqueue_style('bootstrap-select', 'http://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.7.3/css/bootstrap-select.min.css'); 

wp_enqueue_script('bootstrapjs', 'http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', array('jquery'), '', true); 

wp_enqueue_script('bootstrap-selectjs', 'http://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.7.3/js/bootstrap-select.min.js', array('jquery'), '', true); 

回答

0

The problem is described here: Bootstrap-select not working and I know my issue is that I need to make sure bootstrap-select.js is included before loading my code.

What I'm not clear on is how to do this in the wordpress enviornment. I'm close, but not where I want to be. If anyone has a suggestion on how to resolve this, I would appreciate the help.

我猜你的JavaScript文件被加載無論是在header.php文件或主旋律footer.php。當然,他們也可以包含在functions.php中。您可以檢查生成的頁面的源代碼,並檢查包含引導程序選擇的哪個點,然後搜索主題源代碼上的文件名稱。

你是如何入手managematches.js的? 通過使用wp_enqueue_script,您還可以聲明已入隊腳本的依賴性。

+0

謝謝Jukka,它做到了。 – cce1911

相關問題