Advertisement
alchymyth

thumb caption rev3.5

Dec 21st, 2012
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. //POST THUMBNAIL AND CAPTION STYLED SIMILAR TO .wp-caption//
  2. function the_post_thumbnail_and_caption($size = '', $attr = '') {
  3. global $post;
  4. $thumb_id = get_post_thumbnail_id($post->ID);
  5.     $args = array(
  6.         'post_type' => 'attachment',
  7.         'post_status' => null,
  8.         'parent' => $post->ID,
  9.         'include'  => $thumb_id
  10.     );
  11.  
  12. $thumbnail_image = get_posts($args);
  13.  
  14. if ($thumb_id && $thumbnail_image && isset($thumbnail_image[0])) {
  15.     $image = wp_get_attachment_image_src( $thumb_id, $size );
  16.     $image_width = $image[1];
  17.  
  18.     if($attr) $attr_class = $attr['class'];
  19.     $attr['class'] = ''; //move any 'class' attributes to the outer div, and remove from the thumbnail
  20.  
  21.     $output = '<div class="thumbnail-caption attachment-'.$size.($attr?' '.$attr_class:'').'" style="width: ' . ($image_width) . 'px">';
  22.  
  23.     $output .= get_the_post_thumbnail($post->ID, $size, $attr);
  24.  
  25.     /* to show the thumbnail caption */
  26.     $caption = $thumbnail_image[0]->post_excerpt;
  27.     if($caption) {
  28.         $output .= '<p class="thumbnail-caption-text">';
  29.         $output .= $caption;
  30.         $output .= '</p>';
  31.     }
  32.  
  33.     $output .= '</div>';
  34.     }
  35. echo $output;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement