如果先创建数组,然后在循环中添加到其中,会发生什么情况。现在,您不需要添加到数组,只需继续创建它即可。
post\\u名称$args=数组(\'post\\u type\'=>\'storymap\\u事件\',\'posts\\u per\\u page\'=>-1);?>
<div id="mapdiv" style="width: 100%; height: 600px;"></div>
<?php $my_query = null;
$my_query = new WP_Query($args); $i=0;
$sm_array_slides = array();
if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); $i++;
$title = get_the_title();
$excerpt = get_the_excerpt();
$thumb_id = get_post_thumbnail_id();
$thumbnail = wp_get_attachment_image_src($thumb_id,\'\', true);
$latitude = intval(get_post_meta($post->ID, \'wpcf-latitude\', true));
$longitude = intval(get_post_meta($post->ID, \'wpcf-longitude\', true));
$caption = get_post_meta($post->ID, \'wpcf-image-caption\', true);
$credit = get_post_meta($post->ID, \'wpcf-image-credit\', true);
if ( get_post_meta($post->ID, \'wpcf-image-credit\', true )) { $overview = \'overview\'; } else { $overview = \'\'; }
$sm_array_slides [] = array (
$i =>
array (
\'text\' =>
array (
\'headline\' => $title,
\'text\' => $excerpt
),
\'location\' =>
array (
\'name\' => \'Lime street\',
\'lat\' => 53.407615,
\'lon\' => -2.977302,
\'zoom\' => 10,
\'line\' => true,
),
\'media\' =>
array (
\'url\' => \'https://www.youtube.com/watch?v=CCGTR-Oa50Q\',
\'caption\' => \'Example video\',
),
),
);
endwhile; } wp_reset_query();
$sm_array = array (
\'storymap\' =>
array (
\'slides\' => $sm_array_slides
),
);
?>
<?php $json = json_encode($sm_array);?>
<script type="text/javascript">
var storymap_data = <?php echo $json; ?>;
var storymap_options = {};
var storymap = new VCO.StoryMap(\'mapdiv\', storymap_data, storymap_options);
window.onresize = function(event) {
storymap.updateDisplay(); // this isn\'t automatic
}
</script>
你可能需要额外支付
array (
在这条线上:
$sm_array_slides [] = array (
(不要忘记尾随符)
)
但是我不知道你的地图要找的数组格式,所以我没有在代码中删除它。