2016-10-24 3 views
0

私はそれがワードプレスで動作させたいスクリプトファイル(service-graph.js)を持っています。私はかなり基本的なJavaScriptのknowloggeを持っていますので、スクリプトがWordPressで動作するかどうかわかりません。以下:Wordpressでこのスクリプトを呼び出すには?

jQuery(document).ready(function() { 
var url = window.location.pathname; 
var path = url.split('/'); 

jQuery('.curve-item.' + path[2]).addClass('default'); 

if (path[2] == 'blueprint') 
    jQuery('.overview-graph .middle-item').addClass('default'); 

jQuery('.curve-item .logo').hover(
    function() { 
     if (jQuery(this).parent().hasClass('default')) return; 
     jQuery(this).parent().addClass('on'); 
    }, function() { 
     jQuery(this).parent().removeClass('on'); 
    } 
).css('cursor', 'pointer').on('click', function() { 
    location.href = '/services/' + jQuery(this).parent('.curve-item').data('target'); 
}); 

jQuery('.overview-graph .middle-item').on('click', function() { 
    location.href = '/services/blueprint'; 
}).css('cursor', 'pointer'); 

});

そして、私はのfunctions.php

function wpb_adding_scripts() { 
    wp_register_script('service-graph', get_template_directory_uri() . '/js/service-graph.js', array('jquery'), '1.1', true); 
    wp_enqueue_script('service-graph'); 
} 
add_action('wp_enqueue_scripts', 'wpb_adding_scripts'); 
+0

まだテストしていませんか?私はあなたの質問からそのように理解しています。また、/ servicesなどと呼ばれるこのページがjsファイルなので動作するはずです。ワードプレスでは別の方法で動作しません。 – mithataydogmus

+0

はい、テストしましたが、現時点では動作しません。 – Nation

答えて

0

スクリプトでスクリプトを呼び出すために、この機能を使用するには、ワードプレスの中に、さらに呼び出される必要はありません。ブラウザのリソースを調べて、service-graph.jsとjQueryがロードされていることを確認しましたか?私はそれがjQueryバージョンの不一致であると感じています。

関連する問題