gpt4 book ai didi

php - 将样式回显到 google map 和 WordPress 自定义字段的混搭中

转载 作者:行者123 更新时间:2023-12-02 05:29:57 25 4
gpt4 key购买 nike

使用 wordpress,我从特定帖子中提取自定义字段来填写谷歌生成的 map 的内容。我正在使用这段代码

  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;
$snip = get_post_meta($post_id, 'mapExcerpt', true);
echo $title;
echo $snip;
?>')
map.addOverlay(marker);

我试图回显 css 样式 block ,但这会导致 javascript 错误

  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;
$snip = get_post_meta($post_id, 'mapExcerpt', true);
echo "<div class='theTitle'>";
echo $title;
echo "</div>";
echo $snip;
?>')
map.addOverlay(marker);

我收到错误

missing ) after argument list

输出是

     var point = new GLatLng(48.5139,-123.150531);
var marker = createMarker(point,"Lime Kiln State Park",
'<div class='theTitle'>Site Title</div>Site excerpt')
map.addOverlay(marker);

有人可以向我展示一个更优雅(有效)的解决方案吗?

最佳答案

您生成的代码在传递给 createMarker 的单引号内有未转义的单引号。

您需要更改:

echo "<div class='theTitle'>";

至:

echo "<div class=\"theTitle\">";

所以输出将是:

var point = new GLatLng(48.5139,-123.150531);
var marker = createMarker(point,"Lime Kiln State Park",
'<div class="theTitle">Site Title</div>Site excerpt')
map.addOverlay(marker);

关于php - 将样式回显到 google map 和 WordPress 自定义字段的混搭中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2395265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com