Skip to content

Instantly share code, notes, and snippets.

@codehooligans
Created August 1, 2015 13:27
Show Gist options
  • Save codehooligans/171948481d82069931e0 to your computer and use it in GitHub Desktop.
Save codehooligans/171948481d82069931e0 to your computer and use it in GitHub Desktop.
<?php
/*
* Template Name: Facility Map
* Description: Faicility Map Design
*/
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>
<section id="content" <?php if (!env_if_subs($post->ID) && $post->post_parent == 0 ) { echo "class='full-width'"; } ?>>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<div style="display: none;">
<?php $i = 1;
$args = array( 'post_type' => 'facilities', 'posts_per_page' => -1 );
$loop1 = new WP_Query( $args );
while ( $loop1->have_posts() ) : $loop1->the_post();
$terms = get_the_terms( $post->ID, 'facility-category' );
if ( $terms && ! is_wp_error( $terms ) ) :
$markets = array();
foreach ( $terms as $term ) {
$markets[] = $term->name;
}
$markets = join( ", ", $markets );
endif;
$location_name = get_field('location_name');
$perm = get_field('in_permit_process');
if ( $location_name ) : ?>
<div class="mapmark" id="item<?php echo $i; ?>">
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<p class="sub_head">Located in <?php echo $location_name; ?></p>
<?php if ($markets) { ?><p class="sub_head">Market: <?php env_get_tax_page($markets); ?></p><?php } ?>
<?php if ($perm == 'Yes') { ?><p class="sub_head prog">(In Permit Process)</p><?php } ?>
</div>
<?php endif;
$i++;
endwhile; wp_reset_postdata(); ?>
</div>
<script type="text/javascript">
var greenmarker = new google.maps.MarkerImage('<?php bloginfo('stylesheet_directory'); ?>/images/green_Marker.png', new google.maps.Size(25, 35) );
var greymarker = new google.maps.MarkerImage('<?php bloginfo('stylesheet_directory'); ?>/images/grey_Marker.png', new google.maps.Size(25, 35) );
var locations = [
<?php
$args = array( 'post_type' => 'facilities', 'posts_per_page' => -1 );
$loop = new WP_Query( $args );
$i = 1;
while ( $loop->have_posts() ) : $loop->the_post();
$location = get_field('location');
if ((empty($location)) || (!isset($location['lat'])) || (empty($location['lat'])) || (!isset($location['lng'])) || (empty($location['lng']))) {
continue;
}
$latlng = '(' . $location['lat'] . ', ' . $location['lng'] . ')';
if ( $latlng ) : ?>
{
latlng : new google.maps.LatLng<?php echo $latlng; ?>,
info : document.getElementById('item<?php echo $i; ?>'),
ico : <?php if (get_field('in_permit_process') == 'Yes') { ?>greymarker<?php } else { ?>greenmarker<?php } ?>,
},
<?php endif; ?>
<?php $i++; endwhile; ?>
];
</script>
<h3>Find By Location:</h3>
<div id="map" style="width: 100%; height: 400px;"></div>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/in_permit.png" alt="In Permit Process" style="float: right; margin-top: -25px" width="170" height="" />
<h3>Find By Name:</h3>
<ul>
<?php
$args = array( 'post_type' => 'facilities', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => -1 );
$loop2 = new WP_Query( $args );
while ( $loop2->have_posts() ) : $loop2->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php $i++; endwhile; ?>
<?php endwhile; else: ?>
<li><?php _e('Sorry, no posts matched your criteria.'); ?></li>
<?php endif; wp_reset_postdata(); ?>
</ul>
</section><!--content-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment