Advertisement
Guest User

single-branches.php

a guest
Sep 7th, 2014
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.04 KB | None | 0 0
  1. <?php
  2. /**
  3.  * The Template for displaying all Single Branch post.
  4.  *
  5.  */
  6. get_header(); ?>
  7.  
  8. <div class="banner">
  9. <h1><?php the_title(); ?></h1>
  10. </div>
  11.  
  12. <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
  13. <script>
  14.  
  15.   (function($) {
  16.  
  17. /*
  18. *  render_map
  19. *
  20. *  This function will render a Google Map onto the selected jQuery element
  21. *
  22. *  @type  function
  23. *  @date  8/11/2013
  24. *  @since 4.3.0
  25. *
  26. *  @param $el (jQuery element)
  27. *  @return  n/a
  28. */
  29.  
  30.   function render_map( $el ) {
  31.  
  32.     // var
  33.     var $markers = $el.find('.marker');
  34.  
  35.     // vars
  36.     var args = {
  37.       zoom    : 16,
  38.       scrollwheel: false,
  39.       center    : new google.maps.LatLng(0, 0),
  40.       mapTypeId : google.maps.MapTypeId.ROADMAP
  41.     };
  42.  
  43.     // create map
  44.     var map = new google.maps.Map( $el[0], args);
  45.  
  46.     // add a markers reference
  47.     map.markers = [];
  48.  
  49.     // add markers
  50.     $markers.each(function(){
  51.  
  52.         add_marker( $(this), map );
  53.  
  54.     });
  55.  
  56.     // center map
  57.     center_map( map );
  58.  
  59.   }
  60.  
  61.   /*
  62.   *  add_marker
  63.   *
  64.   *  This function will add a marker to the selected Google Map
  65.   *
  66.   *  @type  function
  67.   *  @date  8/11/2013
  68.   *  @since 4.3.0
  69.   *
  70.   *  @param $marker (jQuery element)
  71.   *  @param map (Google Map object)
  72.   *  @return  n/a
  73.   */
  74.  
  75.   function add_marker( $marker, map ) {
  76.  
  77.     // var
  78.     var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') );
  79.  
  80.     // create marker
  81.     var marker = new google.maps.Marker({
  82.       position  : latlng,
  83.       map     : map
  84.     });
  85.  
  86.     // add to array
  87.     map.markers.push( marker );
  88.  
  89.     // if marker contains HTML, add it to an infoWindow
  90.     if( $marker.html() )
  91.     {
  92.       // create info window
  93.       var infowindow = new google.maps.InfoWindow({
  94.         content   : $marker.html()
  95.       });
  96.  
  97.       // show info window when marker is clicked
  98.       google.maps.event.addListener(marker, 'click', function() {
  99.  
  100.         infowindow.open( map, marker );
  101.  
  102.       });
  103.     }
  104.  
  105.   }
  106.  
  107.   /*
  108.   *  center_map
  109.   *
  110.   *  This function will center the map, showing all markers attached to this map
  111.   *
  112.   *  @type  function
  113.   *  @date  8/11/2013
  114.   *  @since 4.3.0
  115.   *
  116.   *  @param map (Google Map object)
  117.   *  @return  n/a
  118.   */
  119.  
  120.   function center_map( map ) {
  121.  
  122.     // vars
  123.     var bounds = new google.maps.LatLngBounds();
  124.  
  125.     // loop through all markers and create bounds
  126.     $.each( map.markers, function( i, marker ){
  127.  
  128.       var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );
  129.  
  130.       bounds.extend( latlng );
  131.  
  132.     });
  133.  
  134.     // only 1 marker?
  135.     if( map.markers.length == 1 )
  136.     {
  137.       // set center of map
  138.         map.setCenter( bounds.getCenter() );
  139.         map.setZoom( 16 );
  140.     }
  141.     else
  142.     {
  143.       // fit to bounds
  144.       map.fitBounds( bounds );
  145.     }
  146.  
  147.   }
  148.  
  149.   /*
  150.   *  document ready
  151.   *
  152.   *  This function will render each map when the document is ready (page has loaded)
  153.   *
  154.   *  @type  function
  155.   *  @date  8/11/2013
  156.   *  @since 5.0.0
  157.   *
  158.   *  @param n/a
  159.   *  @return  n/a
  160.   */
  161.  
  162.   $(document).ready(function(){
  163.  
  164.     $('.acf-map').each(function(){
  165.  
  166.       render_map( $(this) );
  167.  
  168.     });
  169.  
  170.   });
  171.  
  172. })(jQuery);
  173.  
  174. </script>
  175.  
  176.  
  177.  
  178. <div class="content" role="main">
  179.   <div class="inside">
  180.     <div class="map">
  181.   <?php
  182.     $location = get_field('branch_map');
  183.  
  184.     if( !empty($location) ):
  185.     ?>
  186.  
  187.     <div class="acf-map">
  188.       <div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>">
  189.       </div>
  190.     </div>
  191.     <?php endif; ?>
  192. </div>
  193.     <div class="single-branch-details">
  194.       <?php if( have_posts() ) : the_post(); ?>
  195.  
  196.         <h1><?php the_title(); ?></h1>
  197.         <ul>
  198.           <li><span>Address:</span> <?php the_content(); ?></li>
  199.  
  200.           <!-- check if branch-tel is not empty before rendering -->
  201.           <?php if( get_field('branch_tel') ): ?>
  202.           <li><span>Phone:</span> <a href="tel:<?php the_field('branch_tel'); ?>"><?php the_field('branch_tel'); ?></a></li>
  203.           <?php endif; ?>
  204.  
  205.           <!-- check if branch-mobile is not empty before rendering -->
  206.           <?php if( get_field('branch_mobile') ): ?>
  207.           <li><span>Mobile:</span> <a href="tel:<?php the_field('branch_mobile'); ?>"><?php the_field('branch_mobile'); ?></a></li>
  208.           <?php endif; ?>
  209.  
  210.           <?php if( get_field('operation_hours') ): ?>
  211.           <li><span>Operation Hours:</span> <?php the_field('operation_hours'); ?></li>
  212.           <?php endif; ?>
  213.  
  214.           <?php if( get_field('family_section') ): ?>
  215.           <li><span>With</span> Family section</li>
  216.           <?php endif; ?>
  217.         </ul>
  218.       <?php endif; ?>
  219.     </div> <!-- end of .single-branch-details -->
  220.  
  221.     <!-- adds social share buttons -->
  222.     <?php get_ssb($order = array('fblike' => 1, 'twitter' => 2, 'googleplus' => 3)); ?>
  223.  
  224.     <!-- enable comments -->
  225.     <?php comments_template( '', true ); ?>
  226.   </div> <!-- end of .inside -->
  227. </div> <!-- end of .content -->
  228.  
  229. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement