So I set up my wordpress theme to allow users to upload featured images, and Im building my index page to display selected pages' featured images but would also like to display the description of the image.
The thing is, Im not using the loop, Im pulling the page IDs using wordpress's settings API as options.
So displaying the featured images is done like this:
<?php $bucket_options = get_option('frontpage_display_options'); ?>
<?php $page_one = $bucket_options['frontpage_bucket_one']; ?>
<?php $page_one = get_post($page_one); ?>
<?php if (has_post_thumbnail($page_one->ID)) : ?>
<?php echo get_the_post_thumbnail($page_one->ID, 'bucket'); ?>
<?php endif; ?>
I keep reading that this will work:
echo get_post(get_the_post_thumbnail_id($page_one->ID))->post_content;
or this:
echo get_post(get_the_post_thumbnail($page_one->ID))->post_content;
But neither of them displays anything
That capability is awaiting a new release: http://core.trac.wordpress.org/ticket/12235
But a solution that is floating around is to create a function in functions.php:
function the_post_thumbnail_caption() {
global $post;
$thumbnail_id = get_post_thumbnail_id($post->ID);
$thumbnail_image = get_posts(array('p' => $thumbnail_id, 'post_type' => 'attachment'));
if ($thumbnail_image && isset($thumbnail_image[0])) {
echo '<span>'.$thumbnail_image[0]->post_excerpt.'</span>';
}
}
And then call the_post_thumbnail_caption();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With