2014-12-13 29 views
6

WordPress şablonum sayfasındaki bir formda kimin için bir tarih seçkisi istiyorum ama işe yaramıyor. Ben sayfa mypage.php bu ettik SonraJetpress'te jquery datepicker kullanın

function modify_jquery() { 
    if (!is_admin()) { 
     // comment out the next two lines to load the local copy of jQuery 
     wp_deregister_script('jquery'); 
     wp_register_script('jquery', 'http://ajax.googleapis.com/ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js', false, '2.1.1'); 
     wp_enqueue_script('jquery'); 
    } 
} 
add_action('init', 'modify_jquery'); 
function load_jquery_ui_google_cdn() { 
    global $wp_scripts; 

    wp_enqueue_script('jquery-ui-core'); 
    wp_enqueue_script('jquery-ui-slider'); 

    // get the jquery ui object 
    $queryui = $wp_scripts->query('jquery-ui-core'); 

    // load the jquery ui theme 
    $urlui = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.8/jquery-ui.min.js"; 
    wp_enqueue_style('jquery-ui-smoothness', $urlui, false, null); 
} 

add_action('wp_enqueue_scripts', 'load_jquery_ui_google_cdn'); 

:

   <script> 
    $(function() { 
    $("#datepicker").datepicker(); 
    }); 
       </script> 
...other code... 
Date: <input type="text" id="datepicker"> 
...other code... 
     </form> 

Ama göstermiyor

Bu

ben çocuk tema functions.php ettik kodudur . Neyin yanlış olduğunu düşünmeme yardım eder misin?

+0

üzerinde

bakınız ayrıntıları (eğer 'ajax.googleapis.com/ajax.googleapis.com' var). 'Datepicker()' herhangi bir yere dahil ettiniz mi? Ben jQuery UI bir parçası olduğunu düşünüyorum, jQuery değil – Hobo

+0

@Hobo Cevabınız için teşekkürler, ben ilk yazımda gösterildiği gibi jQueryi UI ekledim, ama hala işe yaramıyor, – testermaster

cevap

23

jQuery'yi yüklemek için kullandığınız kod geçersiz ve datepicker (jQuery UI Datepicker) yüklemiyorsunuz. WordPress'te jQuery'yi kullanmanın doğru yolu ile ilgili bir kaç cevap gönderdim, böylece daha fazla okumak isterseniz bir çalışma örneği ve bir bağlantı sağlayacağım.

sizinle çocuğunuz tema functions.php içerisine ekledikten kodu değiştirin: Son olarak birlikte kullanımınızı değiştirmek

/** 
* Load jQuery datepicker. 
* 
* By using the correct hook you don't need to check `is_admin()` first. 
* If jQuery hasn't already been loaded it will be when we request the 
* datepicker script. 
*/ 
function wpse_enqueue_datepicker() { 
    // Load the datepicker script (pre-registered in WordPress). 
    wp_enqueue_script('jquery-ui-datepicker'); 

    // You need styling for the datepicker. For simplicity I've linked to Google's hosted jQuery UI CSS. 
    wp_register_style('jquery-ui', 'http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css'); 
    wp_enqueue_style('jquery-ui'); 
} 
add_action('wp_enqueue_scripts', 'wpse_enqueue_datepicker'); 

:

<script> 
    jQuery(document).ready(function($) { 
     $("#datepicker").datepicker(); 
    }); 
</script> 
yükleme için

jquery requires the word Jquery instead of $

+0

işe başlıyor, teşekkür ederim! Şimdi takvimin arka planında takvimi görüyorum. Burada nasıl varsayılan düzen var? http://jqueryui.com/datepicker/#default – testermaster

+0

İleri gittim ve jQuery UI stil sayfasını yükleme ile ilgili ayrıntıları eklemek için cevabımı güncelledim. –

+0

Güncellemeyi test ettim, önbelleği temizledim, ancak yine de şeffaf arka plan. Sabrınız için teşekkürler. – testermaster

1

senaryoyu & körük stil tema functions.php dosyasına körük kodu ekleyin. ön uç kullanımı arka uç kullanımı

function add_e2_date_picker(){ 
    //jQuery UI date picker file 
    wp_enqueue_script('jquery-ui-datepicker'); 
    //jQuery UI theme css file 
    wp_enqueue_style('e2b-admin-ui-css','http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/themes/base/jquery-ui.css',false,"1.9.0",false); 
    } 
    add_action('admin_enqueue_scripts', 'add_e2_date_picker'); 

için

function add_e2_date_picker(){ 
//jQuery UI date picker file 
wp_enqueue_script('jquery-ui-datepicker'); 
//jQuery UI theme css file 
wp_enqueue_style('e2b-admin-ui-css','http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/themes/base/jquery-ui.css',false,"1.9.0",false); 
} 
add_action('wp_enqueue_scripts', 'add_e2_date_picker'); 

Senaryo için

Senaryo Hemen da funtions.php dosyasını bu kodu koymak ya da o kodu feryat.

function register_datepiker_submenu() { 
    add_submenu_page('options-general.php', 'Date Picker', 'Date Picker', 'manage_options', 'date-picker', 'datepiker_submenu_callback'); 
} 

function datepiker_submenu_callback() { ?> 

    <div class="wrap"> 

    <input type="text" class="datepicker" name="datepicker" value=""/> 

    </div> 

    <script> 
    jQuery(function() { 
     jQuery(".datepicker").datepicker({ 
      dateFormat : "dd-mm-yy" 
     }); 
    }); 
    </script> 

<?php } 
add_action('admin_menu', 'register_datepiker_submenu'); 
?> 

bu kodu ekledikten sonra, Yönetici Menü-> Settigns-> Tarih Seçici üzerinde tarih seçici var edeceğiz. Sizin jQuery URL yanlış görünüyor Add a jQuery DatePicker to WordPress Theme or Plugin