<?php
$args = array(
'post_type' => 'nap',
'posts_per_page' => -1,
);
$the_query = new WP_Query($args);
if ($the_query->have_posts()) {
?>
<div class="selected-default-nap footer-nap" itemscope itemtype="https://schema.org/LegalService">
<div class="d-none">
<p itemprop="name" ><?php bloginfo('name'); ?></p>
<?php $header_logo = get_field('header_logo', 'option'); ?>
<img src="<?php echo $header_logo['url']; ?>" itemprop="image" alt="<?php echo bloginfo('name'); ?>"/>
<span itemprop="priceRange" class="d-none">N/a</span>
</div>
<div class="napDropdown">
<div class="locate-text">Locate Us</div>
<select id="napDropdown">
<?php
$k = 1;
while ($the_query->have_posts()) : $the_query->the_post();
?>
<option value="napvalue<?php echo $k; ?>"><?php the_title(); ?></option>
<?php
$k++;
endwhile;
wp_reset_query();
?>
</select>
</div>
<div class="row justify-content-center" id="dataContainer">
<?php
$i = 1;
while ($the_query->have_posts()) : $the_query->the_post();
$nap_attorney_business_name = get_field('nap_attorney_business_name');
$nap_street_address = get_field('nap_street_address');
$nap_suite_number = get_field('nap_suite_number');
$nap_city_county = get_field('nap_city_county');
$nap_state = get_field('nap_state');
$nap_zip_code = get_field('nap_zip_code');
$nap_phone_number = get_field('nap_phone_number');
$phone_number_post = preg_replace("/[^0-9]/", "", $nap_phone_number);
$nap_fax_number = get_field('nap_fax_number');
$nap_fax_number_preg = preg_replace("/[^0-9]/", "", $nap_fax_number);
$get_directions_link = get_field('get_directions_link');
$address_type = get_field('address_type');
$nap_email_address = get_field('nap_email_address');
$location_image = get_field('location_image');
?>
<div class="col-sm-12 col-md-12 loop-item data-item" data-value="napvalue<?php echo $i; ?>" itemprop="address" itemscope="" itemtype="https://schema.org/PostalAddress">
<div class="inner-item">
<?php
if (!wp_is_mobile()):
if ($location_image):
?><div class="location-image"><?php echo wp_get_attachment_image($location_image['ID'], 'full'); ?></div><?php
endif;
endif;
?>
<div class="nap-address">
<?php
if ($nap_attorney_business_name) {
echo "<div class='nap-title'><span class='b-name'>" . $nap_attorney_business_name . "</span></div>";
}
?>
<?php if ($nap_street_address || $nap_suite_number) { ?>
<span itemprop="streetAddress">
<?php echo $nap_street_address; ?>, <?php echo $nap_suite_number; ?></span>
<?php } ?>
<?php
if ($nap_city_county) {
echo '<br><span itemprop="addressLocality">' . $nap_city_county . ',</span>';
}
?>
<?php if ($nap_state) { ?>
<span itemprop="addressRegion"><?php echo $nap_state; ?></span>
<?php } ?>
<?php
if ($nap_zip_code) {
echo '<span itemprop="postalCode">' . $nap_zip_code . '</span>';
}
?>
<div class="clearfix"></div>
<?php if ($phone_number_post != ''): ?>
<div class="nap-info">
<a href="tel:<?php echo $phone_number_post; ?>">
<span itemprop="telephone">
<?php
if ($nap_phone_number != '') {
echo $nap_phone_number;
}
?>
</span>
</a>
</div>
<?php endif; ?>
<a class="direction-link" href="<?php the_field('get_directions_link') ?>" target="_blank" rel="follow">Get Directions</a>
</div>
<?php if ($nap_fax_number_preg != ''): ?>
<div class="nap-info">
<a href="fax:<?php echo $nap_fax_number_preg; ?>">
<span itemprop="faxNumber">
<?php
if ($nap_fax_number != '') {
echo $nap_fax_number;
}
?>
</span>
</a>
</div>
<?php endif; ?>
</div>
</div>
<?php
$i++;
endwhile;
wp_reset_query();
?>
<div class="col-lg-12"><div id="displayDiv"></div></div>
</div>
<?php if (is_front_page()) { ?>
<div class="d-none" itemscope itemtype="http://schema.org/Place">
<p itemprop="name" ><?php bloginfo('name'); ?></p>
<?php
while ($the_query->have_posts()) : $the_query->the_post();
$latitude = get_field('latitude');
$longitude = get_field('longitude');
?>
<div itemprop="geo" itemscope itemtype="http://schema.org/GeoCoordinates">
<meta itemprop="latitude" content="<?php echo $latitude; ?>" />
<meta itemprop="longitude" content="<?php echo $longitude; ?>" />
</div>
<?php
endwhile;
wp_reset_query();
?>
</div>
<?php } ?>
</div>
<?php } ?>
<?php
function add_script_footer() {
?>
<style>
.data-item {
display: none;
}
.napDropdown {
border-radius: 10px;
border: 1px solid #ccc;
padding: 15px;
width: 100%;
}
.napDropdown .locate-text {
color: #979797;
font-size: 19px;
font-family: 'Montagu Slab 24pt';
line-height: normal;
margin-bottom: 4px;
}
.landing_footer .address_wrap {
display: block !important;
}
.napDropdown select#napDropdown {
color: #fff;
background: none;
box-shadow: none;
border: none;
padding: 0;
padding-left: 0px;
width: 100%;
font-family: 'Montagu Slab 24pt';
font-size: 23px;
text-align: left;
display: block;
}
.napDropdown select#napDropdown option {
color: #000;
}
</style>
<script>
jQuery(document).ready(function () {
function updateDisplay() {
var selectedValue = jQuery('#napDropdown').val();
if (selectedValue) {
var dataItem = jQuery('#dataContainer').find('.data-item[data-value="' + selectedValue + '"]');
var content = dataItem.html();
jQuery('#displayDiv').html(content);
} else {
jQuery('#displayDiv').html('');
}
}
// Initialize display with the first option's data
updateDisplay();
// Update display on dropdown change
jQuery('#napDropdown').on('change', function () {
updateDisplay();
});
});
</script>
<?php
}
add_action('wp_footer', 'add_script_footer');