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;
- $output = '';
- $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];
- $attr_class = '';
- if($attr && isset($attr['class'])) $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>';
- }
- /* //Uncomment to show thumbnail title
- $title = $thumbnail_image[0]->post_title;
- if($title) {
- $output .= '<p class="thumbnail-title-text">';
- $output .= $title;
- $output .= '</p>';
- } */
- /* //Uncomment to show the thumbnail description
- $descr = $thumbnail_image[0]->post_content;
- if($descr) {
- $output .= '<p class="thumbnail-description-text">';
- $output .= $descr;
- $output .= '</p>';
- } */
- /* //Uncomment to show the thumbnail alt field
- $alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true);
- if(count($alt)) {
- $output .= '<p class="thumbnail-alt-text">';
- $output .= $alt;
- $output .= '</p>';
- } */
- $output .= '</div>';
- }
- echo $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement