admin管理员组文章数量:1123926
I'm displaying a featured image (as a background) in a hero div, and using the caption to add some content from the Media Library automatically. I'd also like to use the image's description field and title, but can't find documentation on that. Here's what I have so far, which works as expected:
<div class="hero">
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>
<div class="hero-image" style="background-image: url('<?php echo $thumb['0'];?>')"></div>
<div class="hero-content">
<h1>NEED IMAGE DESCRIPTION HERE</h1>
<p class="caption"><?php get_the_post_thumbnail_caption(); ?><?php the_post_thumbnail_caption(); ?></p>
</div>
</div>
I'm not sure if I'm already getting that info, but not echoing it...or if I need to do more to get it from the database. Thanks in advance for your help!
I'm displaying a featured image (as a background) in a hero div, and using the caption to add some content from the Media Library automatically. I'd also like to use the image's description field and title, but can't find documentation on that. Here's what I have so far, which works as expected:
<div class="hero">
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>
<div class="hero-image" style="background-image: url('<?php echo $thumb['0'];?>')"></div>
<div class="hero-content">
<h1>NEED IMAGE DESCRIPTION HERE</h1>
<p class="caption"><?php get_the_post_thumbnail_caption(); ?><?php the_post_thumbnail_caption(); ?></p>
</div>
</div>
I'm not sure if I'm already getting that info, but not echoing it...or if I need to do more to get it from the database. Thanks in advance for your help!
Share Improve this question asked Feb 10, 2020 at 0:13 GodWordsGodWords 537 bronze badges1 Answer
Reset to default 1this might work:
$post_thumbnail_id = get_post_thumbnail_id($post->ID);
$thumbnail_image = get_posts(array('p' => $post_thumbnail_id, 'post_type' => 'attachment'));
if ($thumbnail_image && isset($thumbnail_image[0])) {
$img_description = $thumbnail_image[0]->post_content;
$img_caption = $thumbnail_image[0]->post_excerpt;
$img_alt = get_post_meta($post_thumbnail_id , '_wp_attachment_image_alt', true);
$img_title = $thumbnail_image[0]->post_title;
}
本文标签:
版权声明:本文标题:post thumbnails - How to display featured image description and title? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736603622a1945275.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论