Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //POST THUMBNAIL AND CAPTION STYLED SIMILAR TO .wp-caption//
- function the_post_thumbnail_and_caption($size = '', $attr = '') {
- global $post;
- $thumb_id = get_post_thumbnail_id($post->ID);
- $args = array(
- 'post_type' => 'attachment',
- 'post_status' => null,
- 'parent' => $post->ID,
- 'include' => $thumb_id
- );
- $thumbnail_image = get_posts($args);
- if ($thumb_id && $thumbnail_image && isset($thumbnail_image[0])) {
- $image = wp_get_attachment_image_src( $thumb_id, $size );
- $image_width = $image[1];
- if($attr) $attr_class = $attr['class'];
- $attr['class'] = ''; //move any 'class' attributes to the outer div, and remove from the thumbnail
- $output = '<div class="thumbnail-caption attachment-'.$size.($attr?' '.$attr_class:'').'" style="width: ' . ($image_width) . 'px">';
- $output .= get_the_post_thumbnail($post->ID, $size, $attr);
- /* to show the thumbnail caption */
- $caption = $thumbnail_image[0]->post_excerpt;
- if($caption) {
- $output .= '<p class="thumbnail-caption-text">';
- $output .= $caption;
- $output .= '</p>';
- }
- $output .= '</div>';
- }
- echo $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement