Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a loop pulling in two different custom post types. I have that loop showing the thumbnails of posts. Each post type used to have its own seperate loop and I had set up some png overlays to sit on top of the thumbnails. I had a play button icon over the thumbnails of the posts in the Video post type, and a stack of pictures icon over the slideshows post type thumbs. Now that I have combined the two loops I need a conditional statement to determine the post type and apply the appropriate overlay.

Here is the code I have that puts the play button over every thumb. How do I change this to a conditional that would apply the btn-play.png over video thumbs and <img src="<?php bloginfo('template_directory'); ?>/images/btn-ss.png" class="play" /> over slideshow thumbs?

<?php $new = new WP_Query(array ('post_type' => array('video', 'slideshow'), 'posts_per_page' => '5')); ?>
   <?php while ($new->have_posts()) : $new->the_post(); ?>
   <!-- BEGIN .post-container -->
   <div class="post-container">
      <div class="post-thumb"> <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'framework'), get_the_title()); ?>">
         <?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) { /* if post has post thumbnail */ ?>
         <?php the_post_thumbnail('thumbnail-ws'); ?>
         <?php } 
            else { ?>
         <?php get_the_image( array( 'custom_key' => array( 'Thumbnail' ), 'width' => 100 ) ); ?>
         <?php } 
                ?>
         <img src="<?php bloginfo('template_directory'); ?>/images/btn-play.png" class="play" /><span>
         <?php the_title('<h2>', '</h2>'); ?>
         <?php the_excerpt(); ?>
         </span> </a> </div>
   </div>
   <?php endwhile; ?>

Any help incorporating this conditional statement would be greatly appreciated.

Just in case anyone is wondering about my code, which probably isn't optimal: I have two tiers of thumbnails so all the old posts where I hadn't specified a Thumbnail will use Justin Tadlock's "get the image script". Also, the weird setup with the span tags is because I have the title and excerpt show on mouseover (with css, no js).

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You can do:

if( 'video' == $post->post_type )
    $play_button = '/images/btn-play.png';
elseif( 'slideshow' == $post->post_type )
    $play_button = '/images/btn-ss.png';

Then render the button with:

<img src="<?php echo get_bloginfo('template_directory') . $play_button; ?>" class="play" />

Hope that helps!

share|improve this answer
    
Thanks! Just a quick follow-up question. I put that conditional statement in the loop. Could I put it in the functions.php file so I could call the $play_button variable in other parts of my theme as well? –  matt Nov 14 '10 at 17:30
    
Yes, you can put it in functions.php. Add global $post; at the top of the function where you put it. –  sorich87 Nov 15 '10 at 6:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.