Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
向Wordpress添加可工作的Javascript谷歌地图代码_Javascript_Php_Wordpress - Fatal编程技术网

向Wordpress添加可工作的Javascript谷歌地图代码

向Wordpress添加可工作的Javascript谷歌地图代码,javascript,php,wordpress,Javascript,Php,Wordpress,我已经看过了所有关于这个的帖子,没有一篇能完全回答我的问题。请帮忙 我有一个工作的Javascript代码,我想插入到我的网站使用Wordpress。我看了很多不同的事情要做,但似乎无法找到正确的解决方案。我是否使用自定义字段?我是否将其发布到博客帖子中并将其插入我的主页 我的代码: <!DOCTYPE html> <html> <head> <style> html, body {height: 100%; m

我已经看过了所有关于这个的帖子,没有一篇能完全回答我的问题。请帮忙

我有一个工作的Javascript代码,我想插入到我的网站使用Wordpress。我看了很多不同的事情要做,但似乎无法找到正确的解决方案。我是否使用自定义字段?我是否将其发布到博客帖子中并将其插入我的主页

我的代码:

 <!DOCTYPE html>
<html>
  <head>
    <style>
      html, body {height: 100%; 
    margin: 1;
        padding: 1;
      }
      #map {
        height: 80%;
      }
    </style>
  </head>
  <body>

    <div id="map"></div>
    <script>

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 2,
    center: {lat: 2, lng: 1.5}
  });

  setMarkers(map);
}

var markers = [
  ['Seoul, South Korea', 37.5667, 126.9667],
  ['Pokhara, Nepal', 28.2639, 83.9722],
  ['Kunming, China', 25.0667, 102.6833],
  ['Busan, South Korea', 35.1667, 129.0667],
  ['Gwangju, South Korea', 35.1667, 126.9167],
  ['Geoje, South Korea', 34.8500, 128.5833],
  ['Toronto, Canada', 43.7000, -79.4000],
  ['Niagara Falls, Canada', 43.1167, -79.0667],
  ['Kitchener, Canada', 43.4500, -80.4833],
  ['Kathmandu, Nepal', 27.7000, 85.3333]
];

var content = ['<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h3 id="firstHeading" class="firstHeading">Seoul, South Korea</h3>'+
      '<div id="bodyContent">'+
      '<p><b>Seoul</b> is the capital of South Korea.' +
      '<br></br><b>Adventure: </b><a href=http://mikenatalieworldwide.com/2015/06/15/hiking-korea-achasan-seoul/>Achasan Mountain</a>", '+
      '<a href=http://mikenatalieworldwide.com/2015/06/04/hiking-korea-gwanaksan-seoul/>Gwanaksan Mountain</a>, '+
  '<br></br><b>Festivals: </b>'+
  '<br></br><b>Food: </b>'+
  '<br></br><b>Places to Stay: </b>'+
  '<br></br><b>Shopping: </b><a href=http://mikenatalieworldwide.com/2015/05/05/around-seoul-namsan-tower/>Namsan Tower</a>, '+
  '<br></br><b>Sightseeing: </b><a href=http://mikenatalieworldwide.com/2015/06/25/around-seoul-jamsil-lotte-world-tower/>Jamsil Lotte World Tower</a>, '+
  '</div>',

'<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h3 id="firstHeading" class="firstHeading">Pokhara, Nepal</h3>'+
      '<div id="bodyContent">'+
      '<p><b>Pokhara</b> is a lake-side city in Nepal.' +
      '<br></br><b>Adventure: </b>, '+
      '<br></br><b>Festivals: </b>'+
      '<br></br><b>Food: </b>'+
      '<br></br><b>Places to Stay: </b>'+
      '<br></br><b>Shopping: </b>'+
      '<br></br><b>Sightseeing: </b>'+
      '</div>', 

'<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h3 id="firstHeading" class="firstHeading">Pokhara, Nepal</h3>'+
      '<div id="bodyContent">'+
      '<p><b>Pokhara</b> is a lake-side city in Nepal.' +
      '<br></br><b>Adventure: </b>, '+
      '<br></br><b>Festivals: </b>'+
      '<br></br><b>Food: </b>'+
      '<br></br><b>Places to Stay: </b>'+
      '<br></br><b>Shopping: </b>'+
      '<br></br><b>Sightseeing: </b>'+
      '</div>', 

'<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h3 id="firstHeading" class="firstHeading">Pokhara, Nepal</h3>'+
      '<div id="bodyContent">'+
      '<p><b>Pokhara</b> is a lake-side city in Nepal.' +
      '<br></br><b>Adventure: </b>, '+
      '<br></br><b>Festivals: </b>'+
      '<br></br><b>Food: </b>'+
      '<br></br><b>Places to Stay: </b>'+
      '<br></br><b>Shopping: </b>'+
      '<br></br><b>Sightseeing: </b>'+
      '</div>', 

'<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h3 id="firstHeading" class="firstHeading">Pokhara, Nepal</h3>'+
      '<div id="bodyContent">'+
      '<p><b>Pokhara</b> is a lake-side city in Nepal.' +
      '<br></br><b>Adventure: </b>, '+
      '<br></br><b>Festivals: </b>'+
      '<br></br><b>Food: </b>'+
      '<br></br><b>Places to Stay: </b>'+
      '<br></br><b>Shopping: </b>'+
      '<br></br><b>Sightseeing: </b>'+
      '</div>', 

'<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h3 id="firstHeading" class="firstHeading">Pokhara, Nepal</h3>'+
      '<div id="bodyContent">'+
      '<p><b>Pokhara</b> is a lake-side city in Nepal.' +
      '<br></br><b>Adventure: </b>, '+
      '<br></br><b>Festivals: </b>'+
      '<br></br><b>Food: </b>'+
      '<br></br><b>Places to Stay: </b>'+
      '<br></br><b>Shopping: </b>'+
      '<br></br><b>Sightseeing: </b>'+
      '</div>',

'<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h3 id="firstHeading" class="firstHeading">Pokhara, Nepal</h3>'+
      '<div id="bodyContent">'+
      '<p><b>Pokhara</b> is a lake-side city in Nepal.' +
      '<br></br><b>Adventure: </b>, '+
      '<br></br><b>Festivals: </b>'+
      '<br></br><b>Food: </b>'+
      '<br></br><b>Places to Stay: </b>'+
      '<br></br><b>Shopping: </b>'+
      '<br></br><b>Sightseeing: </b>'+
      '</div>', 

'<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h3 id="firstHeading" class="firstHeading">Pokhara, Nepal</h3>'+
      '<div id="bodyContent">'+
      '<p><b>Pokhara</b> is a lake-side city in Nepal.' +
      '<br></br><b>Adventure: </b>, '+
      '<br></br><b>Festivals: </b>'+
      '<br></br><b>Food: </b>'+
      '<br></br><b>Places to Stay: </b>'+
      '<br></br><b>Shopping: </b>'+
      '<br></br><b>Sightseeing: </b>'+
      '</div>', 

'<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h3 id="firstHeading" class="firstHeading">Pokhara, Nepal</h3>'+
      '<div id="bodyContent">'+
      '<p><b>Pokhara</b> is a lake-side city in Nepal.' +
      '<br></br><b>Adventure: </b>, '+
      '<br></br><b>Festivals: </b>'+
      '<br></br><b>Food: </b>'+
      '<br></br><b>Places to Stay: </b>'+
      '<br></br><b>Shopping: </b>'+
      '<br></br><b>Sightseeing: </b>'+
      '</div>', 

'<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h3 id="firstHeading" class="firstHeading">Pokhara, Nepal</h3>'+
      '<div id="bodyContent">'+
      '<p><b>Pokhara</b> is a lake-side city in Nepal.' +
      '<br></br><b>Adventure: </b>, '+
      '<br></br><b>Festivals: </b>'+
      '<br></br><b>Food: </b>'+
      '<br></br><b>Places to Stay: </b>'+
      '<br></br><b>Shopping: </b>'+
      '<br></br><b>Sightseeing: </b>'+
      '</div>'
];

function setMarkers(map) {
  // Adds markers to the map.

  for (var i = 0; i < content.length; i++) {
    var marker = markers[i];
    var marker = new google.maps.Marker({
      position: {lat: marker[1], lng: marker[2]},
      map: map,
      title: marker[0]
    });
   attachContent(marker, content[i]);
  }
}

function attachContent(marker, content) {
  var infowindow = new google.maps.InfoWindow({
    content: content
  });

  marker.addListener('click', function() {
    infowindow.open(marker.get('map'), marker);
  });

}
    </script>
    <script async defer
        src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&signed_in=true&callback=initMap"></script>
</body>
</html>

html,身体{身高:100%;
保证金:1;
填充:1;
}
#地图{
身高:80%;
}
函数initMap(){
var map=new google.maps.map(document.getElementById('map'){
缩放:2,
中心:{lat:2,lng:1.5}
});
设置标记(地图);
}
变量标记=[
[韩国首尔,37.5667,126.9667],
['Pokhara,Nepal',28.2639,83.9722],
[中国昆明25.0667102.6833],,
[‘韩国釜山’,35.1667129.0667],
[Gwangju,South Korea',35.1667,126.9167],
[Geoje,韩国,34.8500,128.5833],
[“加拿大多伦多”,43.7000,-79.4000],
['Niagara Falls,Canada',43.1167,-79.0667],
[Kitchener,Canada',43.4500,-80.4833],
[尼泊尔加德满都,27.7000,85.3333]
];
变量内容=[''+
''+
''+
“韩国首尔”+
''+
首尔是韩国的首都+
“

冒险:”,“+ ', '+ “
节日:”+ “
食物:”+ “
住宿地点:”+ “
购物:,”+ “
观光:,”+ '', ''+ ''+ ''+ “博卡拉,尼泊尔”+ ''+ “博卡拉是尼泊尔的湖边城市。”+ “
冒险:,”+ “
节日:”+ “
食物:”+ “
住宿地点:”+ “
购物:”+ “
观光:”+ '', ''+ ''+ ''+ “博卡拉,尼泊尔”+ ''+ “博卡拉是尼泊尔的湖边城市。”+ “
冒险:,”+ “
节日:”+ “
食物:”+ “
住宿地点:”+ “
购物:”+ “
观光:”+ '', ''+ ''+ ''+ “博卡拉,尼泊尔”+ ''+ “博卡拉是尼泊尔的湖边城市。”+ “
冒险:,”+ “
节日:”+ “
食物:”+ “
住宿地点:”+ “
购物:”+ “
观光:”+ '', ''+ ''+ ''+ “博卡拉,尼泊尔”+ ''+ “博卡拉是尼泊尔的湖边城市。”+ “
冒险:,”+ “
节日:”+ “
食物:”+ “
住宿地点:”+ “
购物:”+ “
观光:”+ '', ''+ ''+ ''+ “博卡拉,尼泊尔”+ ''+ “博卡拉是尼泊尔的湖边城市。”+ “
冒险:,”+ “
节日:”+ “
食物:”+ “
住宿地点:”+ “
购物:”+ “
观光:”+ '', ''+ ''+ ''+ “博卡拉,尼泊尔”+ ''+ “博卡拉是尼泊尔的湖边城市。”+ “
冒险:,”+ “
节日:”+ “
食物:”+ “
住宿地点:”+ “
购物:”+ “
观光:”+ '', ''+ ''+ ''+ “博卡拉,尼泊尔”+ ''+ “博卡拉是尼泊尔的湖边城市。”+ “
冒险:,”+ “
节日:”+ “
食物:”+ “
住宿地点:”+ “
购物:”+ “
观光:”+ '', ''+ ''+ ''+ “博卡拉,尼泊尔”+ ''+ “博卡拉是尼泊尔的湖边城市。”+ “
冒险:,”+ “
节日:”+ “
食物:”+ “
住宿地点:”+ “
购物:”+ “
观光:”+ '', ''+ ''+ ''+ “博卡拉,尼泊尔”+ ''+ “博卡拉是尼泊尔的湖边城市。”+ “
冒险:,”+ “
节日:”+ “
食物:”+ “
住宿地点:”+ “
购物:”+ “
观光:”+ '' ]; 函数设置标记(map){ //将标记添加到地图中。 对于(变量i=0;i
在此方面的任何帮助都将不胜感激! 对我来说,这是一个正确的方向。我已经不知疲倦地在谷歌上搜索了这个,但就是想不出来

谢谢!
迈克

你的任务可以用两种不同的方式完成

1) 创建自定义页面模板并将其分配给特定页面,然后将脚本放入该页面的队列中

2) 为地图创建一个简短的代码

我更喜欢第二个选项,因为您可以在任何地方粘贴短代码,所以请按照以下步骤创建短代码

add_shortcode('custom-map-shortcode','custom_map_shortcode_callback'));

function custom_map_shortcode_callback(){
   return '<div id="map"></div>';
}
a) 添加短代码

add_shortcode('custom-map-shortcode','custom_map_shortcode_callback'));

function custom_map_shortcode_callback(){
   return '<div id="map"></div>';
}

将所有这些代码添加到function.php中,然后您就可以在显示地图的任何位置使用快捷代码作为[自定义地图快捷代码]。

您可以通过两种不同的方式完成任务

1) 创建自定义页面模板并将其分配给特定页面,然后将脚本放入该页面的队列中

2) 为地图创建一个简短的代码

我更喜欢第二个选项,因为您可以在任何地方粘贴短代码,所以请按照以下步骤创建短代码

add_shortcode('custom-map-shortcode','custom_map_shortcode_callback'));

function custom_map_shortcode_callback(){
   return '<div id="map"></div>';
}
a) 添加短代码

add_shortcode('custom-map-shortcode','custom_map_shortcode_callback'));

function custom_map_shortcode_callback(){
   return '<div id="map"></div>';
}
将所有这些代码添加到function.php中,然后您就可以在显示地图的任何位置使用快捷码作为[自定义地图快捷码]。

您尝试过输入吗