Title: If/else statement not working as expected
Last modified: August 30, 2016

---

# If/else statement not working as expected

 *  Resolved [icommstudios](https://wordpress.org/support/users/icommstudios/)
 * (@icommstudios)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/ifelse-statement-not-working-as-expected/)
 * Hello! First off thanks for any support given. It’s much appreciated!
 * I have the following code:
 *     ```
       <?php
             if (class_exists('Dynamic_Featured_Image')) {
            global $dynamic_featured_image;
            $featured_images = $dynamic_featured_image->get_featured_images( $postId );
              foreach( $featured_images as $image ) {
                 echo "<img src='{$image['full']}' alt='Dynamic Featured Image' />";
              }
            } else {
               echo wp_get_attachment_image( '7457', 'full' );  //fallback single image
             }
             ?>
       ```
   
 * It appears that the class Dynamic_Featured_Image exists even if there’s not a
   2nd featured image. Therefore my fallback image in the else statement does not
   display. **How can I check if the class exists AND if there is a 2nd featured
   image set?**
 * [https://wordpress.org/plugins/dynamic-featured-image/](https://wordpress.org/plugins/dynamic-featured-image/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Ankit Pokhrel](https://wordpress.org/support/users/ankitpokhrel/)
 * (@ankitpokhrel)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/ifelse-statement-not-working-as-expected/#post-6732750)
 * Hi @icommstudies,
 * You can do something like this:
 *     ```
       <?php
       if (class_exists('Dynamic_Featured_Image')) {
       	global $dynamic_featured_image;
       	$featured_images = $dynamic_featured_image->get_featured_images( $postId );
       	if (!empty($featured_images)) {
       		foreach( $featured_images as $image ) {
       		  echo "<img src='{$image['full']}' alt='Dynamic Featured Image' />";
       		}
       	} else {
       		echo wp_get_attachment_image( '7457', 'full' );  //fallback single image
       	}
       }
       ```
   
 * Regards,
    Ankit

Viewing 1 replies (of 1 total)

The topic ‘If/else statement not working as expected’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/dynamic-featured-image_444643.svg)
 * [Dynamic Featured Image](https://wordpress.org/plugins/dynamic-featured-image/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/dynamic-featured-image/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/dynamic-featured-image/)
 * [Active Topics](https://wordpress.org/support/plugin/dynamic-featured-image/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/dynamic-featured-image/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/dynamic-featured-image/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Ankit Pokhrel](https://wordpress.org/support/users/ankitpokhrel/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/ifelse-statement-not-working-as-expected/#post-6732750)
 * Status: resolved