<!-- Ad Locations -->
<?php 
	global $redux_demo;
	$home_location_disable = $redux_demo['home-location-disable'];
	$locationTitle = $redux_demo['locations-sec-title'];
	$locationDesc = $redux_demo['locations-desc'];
	$locShownBy = $redux_demo['location-shown-by'];
?>
<?php if($home_location_disable == 1) { ?>
<section id="adLocations">
	<div class="row">
		<div class="mainHeading">
			<div class="large-7 medium-8 large-centered medium-centered columns">
				 <h2><?php echo $locationTitle; ?></h2>
				 <p><span class="line"><i class="fa fa-circle"></i></span></p>
				 <p><?php echo $locationDesc; ?></p>
			</div>
		</div>
	</div><!-- END Section Title ROW -->
	<div class="row">
		<div class="mapBg" style="background-image:url(<?php echo esc_url( get_template_directory_uri() ) ; ?>/images/mapbg.png)"></div>
		<div class="areaLocation">
		<?php 
			/*Get Locations Data Start */
			$locationTemplate = $wpdb->get_results("SELECT `post_id` FROM $wpdb->postmeta WHERE `meta_key` ='_wp_page_template' AND `meta_value` = 'template-locations.php' ", ARRAY_A);
			$locationTemplatePermalink ="";
			if(!empty($locationTemplate)){
			$locationTemplatePermalink = get_permalink($locationTemplate[0]['post_id']);
			}
			global $wp_rewrite;
			if ($wp_rewrite->permalink_structure == ''){
			//we are using ?page_id
			$locationURL = $locationTemplatePermalink."&location=";
			}else{
			//we are using permalinks
			$locationURL = $locationTemplatePermalink."?location=";
			}
			$args_location = array( 'posts_per_page' => -1 );
			$lastposts = get_posts( $args_location );
			$all_post_location = array();
			foreach( $lastposts as $post ) {
				$all_post_location[] = get_post_meta( $post->ID, $locShownBy, true );
			}
			$directors = array_unique($all_post_location);
			foreach ($directors as $director) {				
				if(!empty($director)){
			/*Get Locations Data End */
		?>
			<div class="large-3 medium-4 columns end">
				<a href="<?php echo $locationURL; ?><?php echo $director; ?>"><i class="fa fa-map-marker"></i><?php echo $director; ?></a>
			</div>
			<?php }}?>
			<?php wp_reset_query(); ?>
		 </div>
	</div><!-- END Locations Button Row -->
</section>	
<?php }?>
<!-- END Ad Locations -->