0

I hope I get some help with get_template_part function.

  • my starting point is a contact-us template (it's got map+address+emailform) that stores data in the database
  • my other template is where I have put get_template_part( 'contact-us' ).

If taken on its own, the contact-us page works fine (showing data and emailform) but when inserted in the other template then the map+address data are not outputted (yet emailform is working).

What can the problem be? Herewith is the contact-us code:

<?php
/*
 * Template Name: Contact Us Page
 * Description: A Contact Us Page Template for careers theme
 */
get_header(); ?>
<?php include(locate_template('top-header.php')); ?>
<div id="page-content">
<div class="container">
<div class="contenitore">
  <div class="page-content">
    <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
      <?php
        $address = get_post_meta($post->ID, '_meta_box_contact_address', true);
      ?>
      <div class="contact-us">
        <div class="row">
          <div class="col-md-6">
            <center><h3><?php _e('Our', 'globo'); ?><strong><?php _e(' Hq', 'globo'); ?></strong></h3></center>

            <div class="contacy-us-map-section">
              <div id="contact_map_canvas">

              </div>
            </div> <!-- end .map-section -->

            <div class="row">
              <div class="col-sm-6">
                <h5><?php _e('Address Details', 'globo'); ?></h5>

                <div class="address-details clearfix">
                  <i class="fa fa-map-marker"></i>

                    <?php echo apply_filters('the_content',$address); ?>

                </div>

                <div class="address-details clearfix">
                  <i class="fa fa-phone"></i>

                  <p>
                    <span><strong><?php _e('Phone:', 'globo'); ?></strong> <?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_phone', true)); ?></span>
                    <span><strong><?php _e('Fax:', 'globo'); ?></strong> <?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_fax', true)); ?></span>
                  </p>
                </div>

                <div class="address-details clearfix">
                  <i class="fa fa-envelope-o"></i>

                  <p>
                    <span><strong><?php _e('E-mail:', 'globo'); ?></strong> <?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_email', true)); ?></span>
                    <span><span><strong><?php _e('Website:', 'globo'); ?></strong> <?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_website', true)); ?></span></span>
                  </p>
                </div>

              </div>

              <div class="col-sm-6">
                <h5><?php _e('Openig Hours', 'globo'); ?></h5>

                <div class="address-details clearfix">
                  <i class="fa fa-clock-o"></i>

                  <p>
                    <span><strong><?php _e('Mon-Fri:', 'globo'); ?></strong> <?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_opening_mon_fri', true)); ?></span>
                    <span><span><strong><?php _e('Saturday:', 'globo'); ?></strong> <?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_opening_sat', true)); ?></span></span>
                    <span><strong><?php _e('Sunday:', 'globo'); ?></strong> <?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_opening_sun', true)); ?></span>
                  </p>
                </div>

              </div>
            </div> <!-- end .nasted row -->

          </div> <!-- end main grid layout -->

          <div class="col-md-6">
            <center><h3><?php _e('Message', 'globo'); ?><strong><?php _e(' Us', 'globo'); ?></strong></h3></center>

            <div class="contact-form">
              <?php echo do_shortcode(get_post_meta($post->ID, '_meta_box_contact_form_widget', true)); ?>

            </div> <!-- end .contact-form -->

          </div> <!-- end main grid layout -->
        </div> <!-- end .row -->

      </div> <!-- end .contact-us -->
    <?php endwhile; endif; ?>

    <script>
      var txt = '<?php echo esc_url(get_template_directory_uri()); ?>';

      (function($) {
       setTimeout(function(){

       var myMap =  $("#contact_map_canvas").goMap({
          maptype: 'ROADMAP',
          zoom: 10,
          scrollwheel: true,

          markers: [{
            // latitude: 37.793100669930396,
            latitude: '<?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_lat', true)); ?>',
            // longitude: -122.41769313812256,
            longitude: '<?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_lon', true)); ?>',
            icon: txt+'/assets/img/content/map-marker-company.png',
            html: '<?php bloginfo('name'); ?>'
          }]
        });


        google.maps.event.trigger(myMap , 'resize');

        }, 3000);



        // console.log(txt);
      }(jQuery));
    </script>


  </div> <!-- end .page-content -->
  </div> <!-- end .contenitore -->
  </div> <!-- end .container -->

  </div> <!-- end #page-content -->

<?php get_footer(); ?>
  • Is this online? Can you share a url? Also, can you try removing the header and footer calls from this template and then referencing it from the other one? – Kavya Gokul Sep 20 '15 at 18:13
  • I did try removing header-footer but they don't influence the result (except the look of it). Here is the original contact-us page: (agendadelvolo.info/info-point), which I need to insert into this one: agendadelvolo.info/office (view the code, in <!-- start TEST APPENDED CONTACTUS -->) – user72891 Sep 20 '15 at 18:47
0

It's sounds like js errors. Check from chrome console for possible errors.

Also why are you loading the contact-us template using get_template_part function?

| improve this answer | |
  • Thank you for the tip. I initially inserted the whole contact-us code in the other page, and it did work. I'm not a PHP expert but I was looking for something like php_include and discovered that Wordpress uses get_template_part. To me that seemed the correct way or appending one page to another, without adding the whole page code. Is it bad practice? There aren't apparently any js error in the console: the test page is agendadelvolo.info/office (it's ugly because header/footer are included, but the problem is in the address data under the map). – user72891 Sep 21 '15 at 7:30
  • I'm stuck on this, can anyone give me more help? – user72891 Sep 22 '15 at 7:11
  • Can you share your login details? Also what is your website URL? – Rituparna sonowal Sep 23 '15 at 16:23
  • Please understand I cannot share FTP as my client wouldn't like to change his password again. Can you help me just from the outside? What I need to do is insert this page: agendadelvolo.info/info-point into this one: agendadelvolo.info/office which is currently showing the childtheme page with get_template_part in it (included header and footer). – user72891 Sep 25 '15 at 7:44
  • Sorry guys, I have had my PC broken for the whole week. Can anyone help me on this issue still a mistery to me? – user72891 Oct 2 '15 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy