admin管理员组文章数量:1323714
In my theme I want to display the featured image, but I also want to display the title attribute (of the image, not of the post/page) beside the image itself.
Is there a simple way to do this? Where should I be looking?
Thanks, John.
In my theme I want to display the featured image, but I also want to display the title attribute (of the image, not of the post/page) beside the image itself.
Is there a simple way to do this? Where should I be looking?
Thanks, John.
Share Improve this question asked May 11, 2011 at 0:04 John HuntJohn Hunt 3931 gold badge3 silver badges11 bronze badges 1- 1 Can you mark your question as answered since you found the solution. You can answer your own question. This removes it from the unanswered list. – xLRDxREVENGEx Commented May 20, 2011 at 17:54
4 Answers
Reset to default 24post_excerpt is actually the caption attribute. Here is the correct answer:
$title = get_post(get_post_thumbnail_id())->post_title; //The Title
$caption = get_post(get_post_thumbnail_id())->post_excerpt; //The Caption
$description = get_post(get_post_thumbnail_id())->post_content; // The Description
Easy!
<?php the_post_thumbnail();
echo get_post(get_post_thumbnail_id())->post_excerpt; ?>
Taken from: http://www.billerickson/wordpress-featured-image-captions/
Since WordPress 4.6 there are new functions for the post thumbnail caption
Get caption text: (Doc link)
// return the caption text without any html markup
get_the_post_thumbnail_caption();
Output caption text: (Doc link)
// echo the caption text without any html markup
the_post_thumbnail_caption();
You can add a specific post as object or id as parameter. Without (like shown above) WordPress uses the current post.
Try this code to get thumbnail title:
echo get_post(get_post_thumbnail_id())->post_title;
Don't forget to add open and close PHP tag.
本文标签: themesHow can I get the title attribute from getthepostthumbnail()
版权声明:本文标题:themes - How can I get the title attribute from get_the_post_thumbnail()? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742126593a2421971.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论