WordPress サイトでマップをレンダリングするために JQVMaps を使用しています。WordPress の外でコードをテストすると、すべてが完璧に動作します。WordPress に追加すると、次のコンソール エラーが発生しました。
[エラー] TypeError: 'undefined' は関数ではありません ('jQuery('#vmap').vectorMap' を評価しています)
コードは次のとおりです。
header.php:
if (is_page(2)){ ?>
<link href="jqvmap.css" media="screen" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="<?php bloginfo('template_url'); ?>/js/jquery.vmap.js" type="text/javascript"></script>
<script src="<?php bloginfo('template_url'); ?>/js/jquery.vmap.world.js" type="text/javascript"></script>
<script src="<?php bloginfo('template_url'); ?>/js/jquery.vmap.un_regions.js" type="text/javascript"></script>
<script src="<?php bloginfo('template_url'); ?>/js/Chart.js" type="text/javascript"></script>
<?php }?>
<?php wp_head(); ?>
フッター.php:
if (is_page(2)){ ?>
<script type="text/javascript">
// pie chart options
var pieOptions = {
segmentShowStroke : true,
animateScale : false
}
// get pie chart canvas
var pie= document.getElementById("pie").getContext("2d");
jQuery(document).ready(function() { //this is where the error is
jQuery('#vmap').vectorMap({
map: 'world_en',
backgroundColor: '#fff',
borderColor: '#bbb',
borderOpacity: 1,
borderWidth: .2,
color: '#bbb',
colors: colored_regions,
hoverOpacity: 0.8,
selectedColor: '#666666',
enableZoom: false,
showTooltip: false,
onRegionOver : function (element, code, region)
{
highlightRegionOfCountry(code);
},
onRegionOut : function (element, code, region)
{
unhighlightRegionOfCountry(code);
},
onRegionClick: function(element, code, region)
{
highlightRegionOfCountry(code);
$.ajax('/get_chart_data.php', {
data: {region: region},
dataType: 'json',
success: function(response) {
new Chart(pie).Doughnut(response.pieData, pieOptions);
}
});
}
});
});
</script>
<?php }?>
content-page.php ファイルに #vmap と #pie があります。私はすでにいくつかの jQuery.noConflict(); を試しました。これには、$ を ready(function($) に追加すること、スクリプト タグの直後に noConflict 関数を追加することが含まれます。WordPress が jQuery をロードする方法にまだ問題があるのでしょうか、それとも別の問題がありますか?サイトはこちらにあります。ありがとうございます。