• Hi,
    I have a number of tabs on a front-end template that are fed dynamic content from a custom field, however for some products the tabs do not have content. I would like to find a way of only creating the tab if it has content.
    Product info – variable content
    Enquiry form – always has content (contact form 7)
    Video – variable content (youtube embed)

    If the meta info has content I would like to build the tab, if not I would like the tab left off. Code I have so far, which works is:

    <!-- the tabs -->
            <ul class="tabs clearfix">
              <li><a id="t1" href="#tab1">Product Info</a></li>
              <li><a id="t2" href="#tab2">Enquiry Form</a></li>
              <li><a id="t3" href="#tab3">Product Video</a></li>
            </ul>
    
            <!-- tab "panes" -->
            <div class="panes clearfix">
    
              <div>
    						<?php
                  // Get the slug form the term (Eg: Emily)
                  $term_slug = $wp_query->query_vars['product'];
                  // Get the term object based on the slug
                  $term = get_term_by('slug', $term_slug, 'product');
                  // Get the term meta field
                  echo the_field('info');
                  ?>
    					</div>
    
              <div><?php echo do_shortcode( '[contact-form-7 id="96" title="Product Enquiry"]' ); ?></div>
    
              <div>
    
              <iframe width="560" height="315" src="http://www.youtube.com/embed/<?php $term_slug = $wp_query->query_vars['product']; $term = get_term_by('slug', $term_slug, 'product'); echo the_field('product_video'); ?>" frameborder="0" allowfullscreen></iframe>
    
    					</div>
    
            </div>

    This is for hardcoded tabs with the dynamic content inside the pane, however, if the tabs have no content the pane remains empty, which isn’t ideal.

    Any help is much appreciated, I have had a search but cannot find anything that might help.

  • The topic ‘Build tab if has content’ is closed to new replies.