Is there an easy hook to display a featured image with caption (on the blog page)?
add something like :
<?php the_post_thumbnail();
echo ....?
Thank you
How to display a caption to featured image?
Started by
bencloson
, Apr 14 2011 06:36 PM
5 replies to this topic
#1
Posted 14 April 2011 - 06:36 PM
#2
Posted 15 April 2011 - 03:50 AM
I don't think you need external coding for this.
- when you insert an image into a post, fill in the "Caption" field
- and just to the right of the "Insert into Post" button, click the "Use as Featured Image" link
Post back if you're looking for something else.
#3
Posted 20 April 2011 - 05:27 PM
No. This works only for the images inside the post but not for featured Images (at least with PlatFormPro).
I really think that I'll need to add some PHP in the template.postloop.php
Someone could help with code to add?
Thank you
#4
Posted 20 April 2011 - 07:15 PM
You can add the final function from here:
and use the_post_thumbnail_caption() to output in the template.postloop.php file right after any reference to the_post_thumbnail()
#5
Posted 21 April 2011 - 05:39 PM
It worked
Thank you Adam!
#6
Posted 12 October 2011 - 04:35 AM
i tried adding the code
function the_post_thumbnail_caption() {
global $post;
$thumb_id = get_post_thumbnail_id($post->id);
$args = array(
'post_type' => 'attachment',
'post_status' => null,
'post_parent' => $post->ID,
'include' => $thumb_id
);
$thumbnail_image = get_posts($args);
if ($thumbnail_image && isset($thumbnail_image[0])) {
//show thumbnail title
echo $thumbnail_image[0]->post_title;
//Uncomment to show the thumbnail caption
//echo $thumbnail_image[0]->post_excerpt;
//Uncomment to show the thumbnail description
//echo $thumbnail_image[0]->post_content;
//Uncomment to show the thumbnail alt field
//$alt = get_post_meta($thumbnail_id, '_wp_attachment_image_alt', true);
//if(count($alt)) echo $alt;
}
}
from the wordpress forum post mentioned above to the bottom of my functions.php file.
as you may be able to tell, i'm a prrty skanky hack who's just guessing for now. anyway, couldn't get the captions to display on the featured image thumbnails.











