是否有可能(如果是這樣請解釋如何)回聲的PHP到JavaScript,專門爲我的目的我試圖呼應自定義字段從wordpress平臺的輸入到描述的谷歌地圖。我希望我可以給客戶端一個cms後端來輸入地圖上標記點上顯示的文本。我試圖用沒有成功是:回聲的PHP到谷歌地圖javascript
var point = new GLatLng(49.295308,-123.149297);
var marker = createMarker(point,"Site Title",'<div class="maptext"><p class="prepend-top caption">Title<\/p>
<?php $the_query = new WP_Query('category_name=featured');
while ($the_query->have_posts()) : $the_query->the_post();?>
<?php if (get_post_meta($post->ID, 'site-description', true)) { ?>
<?php echo get_post_meta($post->ID, 'site-description', $single = true); ?>
<?php } ?>
<\/div>')
map.addOverlay(marker);
確定sarfaz是對他的一部開拓創新的反應,我得到這是打破它解析錯誤。什麼終於摸索是這樣的:
var point = new GLatLng(48.134239,-122.764769);
var marker = createMarker(point,"Port Townsend Marine Science Center",'<div class="maptext"><?php $the_query = new WP_Query('post_name=test-site');
while ($the_query->have_posts()) : $the_query->the_post();?><?php if (get_post_meta($post->ID, 'map-content', true)) { ?><?php echo get_post_meta($post->ID, "map-content", $single = true); ?><?php } ?><?php endwhile; ?><\/div>')
map.addOverlay(marker);
--- UPDATE ---
只是想補充一點,我覺得這是對我搶的帖子,因爲我總是想一個特定聯繫的最佳方式該標記:
var point = new GLatLng(48.5139,-123.150531);
var marker = createMarker(point,"Lime Kiln State Park",
'<?php $post_id = 182;
$my_post = get_post($post_id);
$title = $my_post->post_title;
echo $title;
echo $my_post->post_content;
?>')
map.addOverlay(marker);
也發佈生成的源代碼;你的JS可能有一個錯誤。 – mpen 2010-03-01 06:58:07
在js中沒有錯誤,至少根據螢火蟲,並且該地圖很好,直到我嘗試注入此php – Zac 2010-03-01 07:43:25