Hide textbox when the fields are empty
-
Hello everyone,
I’ve created a textbox called “Dettagli” where inside I put some custom fields.
when fields are not compiled, they are not displayed in the front-end.
Until this point everything works fine.
Example 1 – fields filled in:
http://oltretutto.altervista.org/motori-a-idrogeno/The problem is that the textbox is not hidden when all fields are empty.
Example 2 – empty fields:
http://oltretutto.altervista.org/lornitorinco/This is the code I used:
<?php // Inizio - Campo immagine ?> <?php $image = get_field('immagine'); if( !empty($image) ): // vars $url = $image['url']; $title = $image['title']; $alt = $image['alt']; $caption = $image['caption']; // thumbnail $size = 'large'; $thumb = $image['sizes'][ $size ]; $width = $image['sizes'][ $size . '-width' ]; $height = $image['sizes'][ $size . '-height' ]; if( $caption ): ?> <div class="wp-caption"> <?php endif; ?> <div class="box-image"><a href="<?php echo $url; ?>" title="<?php echo $title; ?>"> <img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" /> </a></div> <?php if( $caption ): ?> <p class="wp-caption-text"><?php echo $caption; ?></p> </div> <?php endif; ?> <?php endif; ?> <div class="box-dettagli"> <div class="hd-box">Dettagli</div> <div class="box-testo"> <?php // parte 1 ?> <?php if(get_field('storia')) { echo '<div class="box-tipo"><div class="box-campo">Storia: </div><div class="box-risultato">' . get_field('storia') . '</div></div>'; } ?> <?php // parte 2 ?> <?php if(get_field('disegni')) { echo '<div class="box-tipo"><div class="box-campo">Disegni:</div><div class="box-risultato"> ' . get_field('disegni') . '</div></div>'; } ?> <?php // parte 3 ?> <?php $terms = get_field('genere'); if( $terms ): ?> <div class="box-tipo"><div class="box-campo">Genere:</div><div class="box-risultato"><ul class="box-voci"> <?php foreach( $terms as $term ): ?> <li><a href="<?php echo get_term_link( $term ); ?>"><?php echo $term->name; ?></a></li> <?php endforeach; ?></ul></div> </div> <?php endif; ?> <?php // parte 4 ?> <br> <?php if( get_field('correlati') ) { echo "<div>Correlati: " . implode(', ', get_field('correlati')) . "</div>"; } ?></div></div> <?php // Fine ?>
Sorry for my bad English… I understand very little English
- The topic ‘Hide textbox when the fields are empty’ is closed to new replies.