【发布时间】:2012-03-31 23:07:51
【问题描述】:
我正在使用 Wordpress,并且成功地在我的网站上使用 GMaps 显示了带有多个标记的地图。不幸的是,我希望将“位置名称”超链接到我网站上的相关帖子。但由于某种原因,我无法在不破坏整个地图的情况下向信息窗口添加超链接。
下面是功能代码,一旦我删除了strip_tags(); 函数,地图就不再显示。我猜这与" 太多有关,但我不知道如何让它工作。
$str = '';
foreach($loop as $p){
//get the meta and taxonomy data
$name = strip_tags(get_the_term_list($p, "mountains"));
$wtr_long = get_post_meta($p,"wtr_longitude",true);
$wtr_lat = get_post_meta($p,"wtr_latitude",true);
//Add to Array
$map_string .= '{latitude: "' . $wtr_lat . '", longitude: "' . $wtr_long . '", html: "' . $name .'"},~!~';
//$map_string .= '{latitude: "' . $wtr_lat . '", longitude: "' . $wtr_long . '", html: "name"},~!~';
}
//Remove last three "~!~" characters from the string not to have one too many arrays when exploding
$clean_map_string = substr($map_string, 0, -3);
//Now I can use explode on ~!~ to get arrays with my string
$map_array = explode('~!~', $clean_map_string);
?>
<!--Map implementation-->
<div id="map" style="width:880px; height: 600px; background-color:grey;"></div>
<script type="text/JavaScript">
$("#map").gMap({
scrollwheel: false,
maptype: G_PHYSICAL_MAP,
markers: [
<?php
$i = 0;
$length = count($map_array)-1;
//Inserts all the markers
foreach($map_array as $value){
if( $i != $length ){
echo $value;
}
else {
echo str_replace("},", "}],", $value);
}
$i++;
}
?>
popup: false,
zoom: 2 });
</script>
【问题讨论】:
标签: wordpress google-maps google-maps-markers infowindow