222011
 

Google map官方提供了一个地图的嵌入模板,用iframe的,如下:

1
2
<iframe width="640" height="480" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;msa=0&amp;msid=207261559620077253091.0004a3c3df84e74e9b234&amp;ll=3.146138,101.702424&amp;spn=0.041137,0.054932&amp;z=14&amp;output=embed">
</iframe>

但是Wordpress的编辑器在“可视化”和”HTML”切换的时候,会把iframe过滤掉,很让人恼火。没办法,只好自己写脚本。下面脚本可用于Shortcode Exec PHP插件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
extract(
shortcode_atts(
array(
'width' => '600',
'height' => '400',
'frameborder' => '0',
'scrolling' => 'no',
'marginheight' => '0',
'marginwidth' => '0',
'encoding' => 'UTF8',
'lang' => 'en',
'brcurrent' => '',
'msa' => '0',
'msid' => '',
'll' => '',
'spn' => '',
'z' => '14',
'output' => 'embed'
),
$atts)
);

return "<iframe width='$width' height='$height' frameborder='$frameborder' scrolling='$scrolling' marginheight='$marginheight' marginwidth='$marginwidth' src='http://ditu.google.com/maps/ms?ie=$encoding&hl=$lang&brcurrent=$brcurrent&msa=$msa&msid=$msid&ll=$ll&spn=$spn&z=$z&output=$output'></iframe>";

假设模板的名称为ShowGoogleMap,只要在文章中这样调用即可:

[ShowGoogleMap brcurrent="3,0x314f03387538d0a5:0xb84913144116d0f6,0%3B5,0,0" msid="207261559620077253091.0004a3c3df84e74e9b234" ll="3.146172,101.702414" spn="0.034281,0.051413" z="14"]

很方便吧^^,效果如下: