Title: Nested if/else syntax for using diff. thumbnails for diff. post type
Last modified: August 21, 2016

---

# Nested if/else syntax for using diff. thumbnails for diff. post type

 *  [kjcharles](https://wordpress.org/support/users/kjcharles/)
 * (@kjcharles)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/nested-ifelse-syntax-for-using-diff-thumbnails-for-diff-post-type/)
 * Hello,
 * I have a site that has 2 multimedia post types:
    $media_type = ‘audio’; $media_type
   = ‘video’; and the site should pull the youtube thumbnail for the ‘video’ type
   and the post thumbnail for the ‘audio’ type, however, there isn’t any if/else
   statement to distinguish between the two types for what image to use (this was
   built by someone else and I’m trying to fix it).
 * I’m not sure (a.) if I should have the function inside functions.php do this 
   or if it should be at the page template level.
 * This is what I have in functions.php — which tells WP to get one thing for ‘video’
   but doesn’t tell it what to do for ‘audio’
 *     ```
       function abc_media_thumbnail() { ?>
       	<div class="thumb">
       	  <!-- RUN TIME, CAST, etc... -->
       	  <a>">
       	    <?php $media_type = 'video';
       	        get_youtube_thumbnail(get_field('media_url'));
   
       	        $runtime = get_field('length');
       	    ?>
       	  </a>
   
       	  <?php if (!empty($runtime)): ?>
       	  	<div class="runtime"><?php echo $runtime; ?></div>
       	  <?php endif; ?>
   
       	  <div class='media-info'>
       	    <p class='title'><a>"> <?php the_title(); ?></a></p>
       	    <p class="date grayed"><?php the_time('F j, Y'); ?></p>
       	  </div>
       	</div>
       <?php
       }
   
       This is what the page template has:
   
       <?php get_header();
       $url = get_bloginfo('url'); ?>
   
       <div id="content">
         <?php if ( have_posts() ) while ( have_posts() ): the_post(); ?>
       	  <?php
       	  		$media_terms = get_the_terms($post->ID, 'media-type');
   
       	  		if (is_array($media_terms)) {
       	  			$media_type = array_pop($media_terms);
       	  		}
       	  ?>
   
       	  <?php if (isset($media_type)): ?>
   
       		    <div class="labels">
       		      <a>slug; ?>"><?php echo $media_type->name; ?></a>
       		    </div>
       		    <div id="media" class="clearfix">
       		      <?php
       		        if ($media_type->slug == 'video') {
       		          abc_video_post();
       		        } else {
       		          abc_audio_post();
       		        }
       		      ?>
       		    </div>
   
       	  <?php endif; ?>
   
         <?php endwhile;
           wp_reset_postdata();
         ?>
   
         <?php if (isset($media_type)): ?>
   
       	  <h2 class="recent">Recently Featured</h2>
       	  <?php
       	    $args = array(
       	      'posts_per_page' => 4,
       	      'post__not_in' => array($post->ID),
       	      'tax_query' => array(
       	        array(
       	          'taxonomy' => 'media-type',
       	          'field' => 'slug',
       	          'terms' => $media_type->slug
       	        )
       	      )
       	    );
       	    $recent_posts = new WP_Query( $args );
       	    if ( $recent_posts->have_posts() ) while ( $recent_posts->have_posts() ): $recent_posts->the_post();
       	      abc_media_thumbnail();
       	    endwhile; ?>
   
         <?php endif; ?>
   
       </div>
   
       <?php get_sidebar(); ?>
   
       <?php get_footer(); ?>
       ```
   
 * _[Moderator Note: Please post code or markup between backticks or use the code
   button. Or better still – use a [pastebin](http://pastebin.com/). Your posted
   code has now been **permanently damaged** by the forum’s parser.]_
 * Any help is much appreciated!

The topic ‘Nested if/else syntax for using diff. thumbnails for diff. post type’
is closed to new replies.

## Tags

 * [Conditions](https://wordpress.org/support/topic-tag/conditions/)
 * [ifelse](https://wordpress.org/support/topic-tag/ifelse/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [kjcharles](https://wordpress.org/support/users/kjcharles/)
 * Last activity: [12 years, 8 months ago](https://wordpress.org/support/topic/nested-ifelse-syntax-for-using-diff-thumbnails-for-diff-post-type/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
