是否有一个函数来获取在WordPress的图像标题(Is there a function to g

2019-08-31 21:31发布

我试图从图像的WordPress的标题,但我无法找到一个简单的功能,抓住信息这一点。

任何人都知道一种方式来获得吗?

谢谢

Answer 1:

如果你想获得的标题,而在后,你可以重复它从你的“the_post_thumbnail”标签内。

<?php the_post_thumbnail();
echo get_post(get_post_thumbnail_id())->post_excerpt; ?>

你也可以用同样的方法来显示图像的描述。 这是在WordPress 3.5好一点的功能

<?php the_post_thumbnail();
echo get_post(get_post_thumbnail_id())->post_content; ?>

如果您需要样式的标题或说明你可以用它在一个div像下面。

<?php the_post_thumbnail();
    echo '<div class="myDiv">' . get_post(get_post_thumbnail_id())->post_excerpt . '</div>'
; ?>

希望帮助。



Answer 2:

原来字幕存储为帖子摘录。 所以,

<?php echo $post->post_excerpt; ?>

如果你是添加图像页面(在你的主题image.php)上,并在循环内将打印出的标题。



Answer 3:

使用WordPress 4.8,这个小家伙为我工作:

<?php the_post_thumbnail_caption(); ?>


Answer 4:

我使用这个代码,它工作正常。

$get_description = get_post(get_post_thumbnail_id())->post_excerpt; if(!empty($get_description)){//If description is not empty show the div    echo '<div class="img-caption">' . $get_description . '</div>'; }


Answer 5:

把你的single.php文件的这里面的数字标签

$image_caption = get_post(get_post_thumbnail_id())->post_excerpt;
if(!empty($image_caption)) { 
    echo '<figcaption itemprop="caption">' . $image_caption . '</figcaption>'; 
}


文章来源: Is there a function to get the caption for an image in wordpress