如何让metatag'cp_address'调用gmap?

时间:2012-08-01 11:26:32

标签: php wordpress google-maps

以下脚本编译广告客户字段'cp_street','cp_city'和'cp_state'以创建调用我网站上的侧边栏地图的地址。我创建了一个名为'cp_address'的新字段,用户可以在其中键入完整的地址。如何更改下面的脚本以便两个工作?

   <?php
// check to see if ad is legacy or not and then assemble the map address
if ( get_post_meta($post->ID, 'location', true) )
    $make_address = get_post_meta($post->ID, 'location', true);
else
    $make_address = get_post_meta($post->ID, 'cp_street', true) . '&nbsp;' . get_post_meta($post->ID, 'cp_city', true) . '&nbsp;' . get_post_meta($post->ID, 'cp_state', true) . '&nbsp;' . get_post_meta($post->ID, 'cp_zipcode', true);

    $coordinates = cp_get_geocode( $post->ID );
?>

<script type="text/javascript">var address = "<?php echo esc_js($make_address); ?>";</script>

    <?php cp_google_maps_js($coordinates); ?>

1 个答案:

答案 0 :(得分:0)

<?php
// check to see if ad is legacy or not and then assemble the map address
$make_address = get_post_meta($post->ID, 'cp_address', true);
if ( !$make_address || empty($make_address) )
    $make_address = get_post_meta($post->ID, 'cp_street', true) . '&nbsp;' . get_post_meta($post->ID, 'cp_city', true) . '&nbsp;' . get_post_meta($post->ID, 'cp_state', true) . '&nbsp;' . get_post_meta($post->ID, 'cp_zipcode', true);

    $coordinates = cp_get_geocode( $post->ID );
?>

<script type="text/javascript">
var address = "<?php echo esc_js($make_address); ?>";
</script>

<?php cp_google_maps_js($coordinates); ?>