Support » Fixing WordPress » Nested if/else 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... -->
    	    <?php $media_type = 'video';
    	        $runtime = get_field('length');
    	  <?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>
    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(); ?>
    	  		$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 id="media" class="clearfix">
    		        if ($media_type->slug == 'video') {
    		        } else {
    	  <?php endif; ?>
      <?php endwhile;
      <?php if (isset($media_type)): ?>
    	  <h2 class="recent">Recently Featured</h2>
    	    $args = array(
    	      'posts_per_page' => 4,
    	      'post__not_in' => array($post->ID),
    	      'tax_query' => 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();
    	    endwhile; ?>
      <?php endif; ?>
    <?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. 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.