php解析错误:语法错误,意外'src'(T_STRING)

时间:2016-03-13 21:12:55

标签: wordpress google-maps infowindow advanced-custom-fields

我在查明如何从自定义帖子中提取特色图片方面遇到了一些麻烦。

我收到以下错误:

Parse error: syntax error, unexpected 'src' (T_STRING) 

如何正确地逃避这一点,以便特色图像回显到信息窗口?

这是我的代码:

     <!--Start Map-->
  <div class="col-md-6">
        <?php
        $args = array(
          'post_type'   => 'listings',
          'posts_per_page'  => -1
        );
            // query
            $wp_query = new WP_Query( $args );
            $NUM = 0;
            ?>

          <div id="map"></div>
              <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>

            <script type="text/javascript">
                var locations = [<?php while( $wp_query->have_posts() ){
              $wp_query->the_post();
                $location = get_field('address'); 
            ?>

          ['<?php echo("<a href=\"".get_the_permalink()."\" >"<img src="\".get_$thumbnail_url[0]"\"</a>"); ?>', <?php echo $location['lat']; ?>, <?php echo $location['lng'];?>, <?php $NUM++ ?>],
            <?php } ?> ];

                var map = new google.maps.Map(document.getElementById('map'), {
                  zoom: 13,
                  zoomControl: true,
                  scaleControl: false,
                  panControl: false,
                  scrollwheel: false, /*disable mouseover grab*/
                  center: new google.maps.LatLng(40.6912527,-73.9464121), /* center map location*/
                  mapTypeId: google.maps.MapTypeId.ROADMAP
                });
                var transitLayer = new google.maps.TransitLayer();
                                transitLayer.setMap(map);

                var infowindow = new google.maps.InfoWindow();

                var marker, i;

                for (i = 0; i < locations.length; i++) {
                  marker = new google.maps.Marker({
                    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
                    map: map
                  });

                  google.maps.event.addListener(marker, 'click', (function(marker, i) {
                    return function() {
                      infowindow.setContent(locations[i][0]);
                      infowindow.open(map, marker);
                    }
                  })(marker, i));
                }
             </script>
        </div>
  </div><!--end col map -->

1 个答案:

答案 0 :(得分:0)

错误来自该代码块:

var locations = [<?php while( $wp_query->have_posts() ){
          $wp_query->the_post();
            $location = get_field('address'); 
        ?>

      ['<?php echo("<a href=\"".get_the_permalink()."\" >"<img src="\".get_$thumbnail_url[0]"\"</a>"); ?>', <?php echo $location['lat']; ?>, <?php echo $location['lng'];?>, <?php $NUM++ ?>],
        <?php } ?> ];

您应该使用更多缩进来更清晰地查看代码。这是固定版本(我希望):

var locations = [
<?php while( $wp_query->have_posts() ) : ?>
    <?php $wp_query->the_post(); ?>
    <?php $location = get_field('address'); ?>

    [
      '<?php echo "<a href=\"".get_the_permalink()."\" ><img src=\"".get_thumbnail_url[0]."\"></a>"; ?>',
      <?php echo $location['lat']; ?>,
      <?php echo $location['lng'];?>,
      <?php $NUM++ ?>
    ],

<?php endwhile; ?> 
];