[wp-edu] Need help with code to select right image

Charles, Kimberly kbaxa at uic.edu
Tue Sep 24 20:32:17 UTC 2013


Hello --

I need help with some custom code for my WordPress site. 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 (b.) 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(); ?>

Any help is much appreciated!
Kim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.automattic.com/pipermail/wp-edu/attachments/20130924/bbb759d1/attachment.html>


More information about the wp-edu mailing list