Support

Account

Home Forums Add-ons Repeater Field Cleaner way to hide empty fields? Reply To: Cleaner way to hide empty fields?

  • cleaner is in the eye of the beholder. Shorter with less IFs

    
    <?php 
    
      if (have_rows('new_music_submissions')) {
        while (have_rows('new_music_submissions')) {
          the_row();
          echo '<h3>'; the_sub_field('band_name'); echo '</h3>';
          echo '<img class="band-logo" src="'; the_sub_field('band_logoimage'); echo '">';
            the_sub_field('band_blurb');
            the_sub_field('band_media_clip');
            echo '<div class="band-links">';
            $subfields = array(
              'band_official_site' => '/icons/firefox.png',
              'band_facebook' => '/icons/facebook.png',
              'band_twitter' => '/icons/TED.png',
              'band_youtube' => '/icons/youtube.png',
              'band_googleplus' => '/icons/googlep.png',
              'band_itunes' => '/icons/linkedin.png',
              'band_spotify' => '/icons/spotify.png',
              'band_soundcloud' => '/icons/soundcloud.png',
              'band_bandcamp' => '/icons/VLC.png',
              'band_reverbnation' => '/icons/steam.png',
              'band_myspace' => '/icons/myspace.png',
              'band_amazon' => '/icons/adobe.png',
              'band_instagram' => '/icons/instagram.png',
              'band_lastfm' => '/icons/lastfm.png'
            ); // end array
            foreach ($subfields as $field => $image) {
              $value = get_sub_field($field);
              if ($value) {
                echo '<a href="'.$value.'"><img src="'.get_template_directory_uri().$image.'"></a>';
              }
            } // end foreach field
            echo '</div>';
        } // end while
      } else {
        echo "No bands found";
      }
    ?>