• Hi,
    I’m trying to follow the steps here to display several thumbnails in my theme using customs fields.

    I have it working now so it will display several custom fields with the name “image”. See my code here:

    <?php
    
    $mykey_values = get_post_custom_values('image');
    foreach ( $mykey_values as $key => $value ) {
    echo '<img src="'.$value.'">';
    }
    ?>

    My problem is if there is no custom field with the “image” name then I get a PHP error. How do I make this an if statement? Obviously my PHP skills are bad. Thanks!

Viewing 1 replies (of 1 total)
  • try this

    <?php
    $mykey_values = get_post_custom_values('image');
    if ($mykey_values) {
      foreach ( $mykey_values as $key => $value ) {
        echo '<img src="'.$value.'">';
      }
    }
    ?>

Viewing 1 replies (of 1 total)

The topic ‘Custom Fields – PHP If Statment’ is closed to new replies.