简体   繁体   English

header.php中的WordPress,GoogleMaps和JavaScript

[英]WordPress, GoogleMaps & JavaScript in header.php

I would like to display a GoogleMap with multiple pointers in the entry page of a WordPress website (www.santini.se/geotimes). 我想在WordPress网站(www.santini.se/geotimes)的入口页面中显示带有多个指针的GoogleMap。 I specified the following Javascript code within the head of header.php: 我在header.php头中指定了以下Javascript代码:

 <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=mykey"  type="text/javascript"></script>
 <script src="map_data.php" type="text/javascript"></script>
 <script src="map_functions.js" type="text/javascript"></script>

Then I specified a div just after the body tag in header.phh: 然后我在header.phh中的body标签之后指定了一个div:

  http://www.santini.se/prova/listOfPontersCh2/http://www.santini.se/prova/listOfPontersCh2/<div id="map" style="width: 350px; height: 350px; border: blue 4px dashed">whyyyy</div>

The files map_data.php and map_functions.js are placed in the same folder as header.php. map_data.php和map_functions.js文件与header.php放在同一文件夹中。

This code works correctly outside WordPress. 此代码可在WordPress外部正常工作。 You can see it here: http://www.santini.se/prova/listOfPontersCh2/ 您可以在这里看到它: http : //www.santini.se/prova/listOfPontersCh2/

Why is it not working within WordPress? 为什么它在WordPress中不起作用?

Any hint would help :-( 任何提示都会有所帮助:-(

Thanks in advance 提前致谢

Regards 问候

Marina 码头

I think your scripts aren't linked properly. 我认为您的脚本未正确链接。 The URI in the scr-attribute must be relative to the current URL, not to the PHP-file. scr属性中的URI必须相对于当前URL,而不是相对于PHP文件。

If your theme is 'prosumer', this would probably solve it: 如果您的主题是“生产者”,则可能可以解决该问题:

<script src="http://www.santini.se/geotimes/wp-content/themes/prosumer/map_data.php" type="text/javascript"></script>
<script src="http://www.santini.se/geotimes/wp-content/themes/prosumer/map_functions.js" type="text/javascript"></script>

Or you could do it programmatically (which I prefer): 或者,您可以通过编程方式来做到这一点(我更喜欢):

<script src="<?php bloginfo('template_directory'); ?>/map_data.php" type="text/javascript"></script>
<script src="<?php bloginfo('template_directory'); ?>/map_functions.js" type="text/javascript"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM