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

Covello, Steve Steve.Covello at granite.edu
Tue Sep 24 20:44:51 UTC 2013


Sorry I can't help, but you might also get a good response from Stackexchange.com's wordpress thread.

http://wordpress.stackexchange.com/

That way, your answer will be preserved for the rest of the WP community to draw from as well – not just the weasels in this group  ;-)

Thx – Steve

--
Steve Covello
Rich Media Specialist/Online Instructor
Chalk & Wire Administrator
Granite State College
603-513-1346
Skype: steve.granitestate
Scheduling: http://meetme.so/stevecovello


From: <Charles>, Kimberly <kbaxa at uic.edu<mailto:kbaxa at uic.edu>>
Reply-To: "Low-traffic list discussing WordPress in education." <wp-edu at lists.automattic.com<mailto:wp-edu at lists.automattic.com>>
Date: Tuesday, September 24, 2013 4:32 PM
To: "Low-traffic list discussing WordPress in education." <wp-edu at lists.automattic.com<mailto:wp-edu at lists.automattic.com>>
Subject: [wp-edu] Need help with code to select right image

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/d6a34cef/attachment-0001.html>


More information about the wp-edu mailing list