Support

Account

Home Forums Front-end Issues Show ACF only if they exists in a div Reply To: Show ACF only if they exists in a div

  • 
    <?php 
      $fields = get_fields();
      if ($fields) {
        foreach ($fields as $field => $value) {
          if ($value) {
            ?>
              <div>
                <h3><?php echo $name; ?></h3>
                <?php 
                  switch ($name) {
                    case 'case':
                      $src = 'url for this field name';
                      break;
                    case 'for':
                      $src = 'url for this field name';
                      break;
                    case 'every':
                      $src = 'url for this field name';
                      break;
                    case 'possible':
                      $src = 'url for this field name';
                      break;
                    case 'field':
                      $src = 'url for this field name';
                      break;
                    case 'name':
                      $src = 'url for this field name';
                      break;
                    default:
                      // default for all field names not listed above
                      $src = 'default url';
                  } // end switch
                ?>
                <img src="<?php echo $src; ?>" />
                <p><?php echo $value; ?></p>
              </div>
            <?php 
          } // end if $value
        } // end foreach field
      } // end if fields
    ?>