Skip to content

Instantly share code, notes, and snippets.

@JacobHsu
Created September 2, 2013 03:09
Show Gist options
  • Save JacobHsu/6408901 to your computer and use it in GitHub Desktop.
Save JacobHsu/6408901 to your computer and use it in GitHub Desktop.
wordpress/wp-content/themes/
<title><?php echo get_stylesheet_directory_uri() ?></title>
<?php get_header(); ?>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri() ?>/map.js"></script>
<?php $page_for_posts = get_option( 'page_for_posts' );?>
<!--分頁內輸出 文章內容-->
<?php
$args = array( 'numberposts' => 3 );
$lastposts = get_posts( $args );
foreach($lastposts as $post) : setup_postdata($post); ?>
<h3><?php echo "post->ID:".$post->ID; ?></h3>
<?php echo get_geocode_latlng($post->ID)."===".$post->ID.","; //$post->ID=1; ?>
<?php endforeach; ?>
<body onload="initialize()">
<?php if ( have_posts() ) : ?> <!--輸出文章網址-->
<!-- WordPress has found matching posts -->
<div style="display: none;">
<?php $i = 1; ?>
<!--Page輸出文章網址-->
<?php
$args = array( 'numberposts' => 3 );
$lastposts = get_posts( $args );
foreach($lastposts as $post) : setup_postdata($post); ?>
<?php //if ( get_post_meta($post->ID, 'latlng', true) !== '' ) : ?>
<?php //使用 Address Geocoder plugin 這裡要修正 ?>
<?php if ( get_geocode_latlng($post->ID) !== '' ) : ?>
<div id="item<?php echo $post->ID; ?>">
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<?php the_content(); ?>
</div>
<?php endif; ?>
<?php $i++; ?>
<?php endforeach; ?>
</div>
<script type="text/javascript">
<?php// locations 傳給map.js ?>
var locations = [
<?php
$args = array( 'numberposts' => 3 );
$lastposts = get_posts( $args );
foreach($lastposts as $post) : setup_postdata($post); ?>
<?php// if ( get_post_meta($post->ID, 'latlng', true) !== '' ) : ?>
<?php //使用 Address Geocoder plugin 這裡要修正 ?>
<?php if ( get_geocode_latlng($post->ID) !== '' ) : ?>
{
//latlng : new google.maps.LatLng<?php echo get_post_meta($post->ID, 'latlng', true); ?>,
//使用 Address Geocoder plugin 這裡要修正
latlng : new google.maps.LatLng<?php echo get_geocode_latlng($post->ID); ?>,
info : document.getElementById('item<?php echo $post->ID; ?>')
},
<?php endif; ?>
<?php $i++; ?>
<?php endforeach; ?>
];
</script>
<!-- Google Map -->
<div id="map_canvas" style="width: 100%; height: 100%;"></div>
<?php else : ?>
<!-- No matching posts, show an error -->
<h1>Error 404 &mdash; Page not found.</h1>
<?php endif; ?>
<?php //get_footer(); ?>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment