<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: Calibri, sans-serif; ">
<div>Hello --</div>
<div><br>
</div>
<div>I need help with some custom code for my WordPress site. I have a site that has 2 multimedia post types:</div>
<div>
<div>$media_type = 'audio';</div>
<div>$media_type = 'video';</div>
<div>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).</div>
<div><br>
</div>
<div>I'm not sure (a.) if I should have the function inside functions.php do this or if (b.) it should be at the page template level.</div>
<div><br>
</div>
<div>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'</div>
<div><br>
</div>
<div>function abc_media_thumbnail() { ?></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span><div class="thumb"></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <!-- RUN TIME, CAST, etc... --></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <a>"></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <?php $media_type = 'video';</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> get_youtube_thumbnail(get_field('media_url'));</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> $runtime = get_field('length');</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> ?></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> </a></div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <?php if (!empty($runtime)): ?></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <span class="Apple-tab-span" style="white-space:pre">
</span><div class="runtime"><?php echo $runtime; ?></div></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <?php endif; ?></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <div class='media-info'></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <p class='title'><a>"> <?php the_title(); ?></a></p></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <p class="date grayed"><?php the_time('F j, Y'); ?></p></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> </div></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span></div></div>
<div><?php</div>
<div>}</div>
<div><br>
</div>
<div>This is what the page template has:</div>
<div><br>
</div>
<div><?php get_header();</div>
<div>$url = get_bloginfo('url'); ?></div>
<div><br>
</div>
<div><div id="content"></div>
<div> <?php if ( have_posts() ) while ( have_posts() ): the_post(); ?></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <?php</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <span class="Apple-tab-span" style="white-space:pre">
</span>$media_terms = get_the_terms($post->ID, 'media-type');</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <span class="Apple-tab-span" style="white-space:pre">
</span>if (is_array($media_terms)) {</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <span class="Apple-tab-span" style="white-space:pre">
</span>$media_type = array_pop($media_terms);</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <span class="Apple-tab-span" style="white-space:pre">
</span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> ?></div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <?php if (isset($media_type)): ?></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <div class="labels"></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <a>slug; ?>"><?php echo $media_type->name; ?></a></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> </div></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <div id="media" class="clearfix"></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <?php</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> if ($media_type->slug == 'video') {</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> abc_video_post();</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> } else {</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> abc_audio_post();</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> }</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> ?></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> </div></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <?php endif; ?></div>
<div> <?php endwhile;</div>
<div> wp_reset_postdata();</div>
<div> ?></div>
<div><br>
</div>
<div> <?php if (isset($media_type)): ?></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <h2 class="recent">Recently Featured</h2></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> <?php</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> $args = array(</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> 'posts_per_page' => 4,</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> 'post__not_in' => array($post->ID),</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> 'tax_query' => array(</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> array(</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> 'taxonomy' => 'media-type',</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> 'field' => 'slug',</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> 'terms' => $media_type->slug</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> )</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> )</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> );</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> $recent_posts = new WP_Query( $args );</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> if ( $recent_posts->have_posts() ) while ( $recent_posts->have_posts() ): $recent_posts->the_post();</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> abc_media_thumbnail();</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span> endwhile; ?></div>
<div> <?php endif; ?></div>
<div></div></div>
<div><?php get_sidebar(); ?></div>
<div><?php get_footer(); ?></div>
</div>
<div><br>
</div>
<div>Any help is much appreciated!</div>
<div>Kim</div>
</body>
</html>