wordpress 有没有获取图片标题的函数

发布于 2024-08-08 23:25:39 字数 87 浏览 3 评论 0原文

我正在尝试从 Wordpress 中的图像中获取标题,但我找不到一个简单的函数来获取这些信息。

有人知道有办法得到这个吗?

谢谢

I'm trying to get the captions from images in Wordpress but I can't find an easy function to grab this bit of information.

Anyone know a way to get this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

爱的故事 2024-08-15 23:25:39

如果您想在帖子中获取标题,您可以在“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>'
; ?>

希望有帮助。

If you are trying to get the caption while in a post you can echo it out inside your "the_post_thumbnail" tag.

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

You can also use the same method to show the image description. This is a little better feature in WordPress 3.5

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

If you need to style the caption or description you can wrap it in a div like below.

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

Hope that helps.

冬天的雪花 2024-08-15 23:25:39

结果标题被存储为帖子摘录。因此,

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

如果您位于附件图像页面(主题中的 image.php)并且位于循环内,则会打印出标题。

Turns out captions are stored as post excerpts. So,

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

will print out the caption if you are on the attachment image page (image.php in your theme) and inside the Loop.

如歌彻婉言 2024-08-15 23:25:39

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

<?php the_post_thumbnail_caption(); ?>

Using Wordpress 4.8, this little guy worked for me:

<?php the_post_thumbnail_caption(); ?>
只为一人 2024-08-15 23:25:39

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

$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>'; }

I'm using this code, It works fine.

$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>'; }
偏爱自由 2024-08-15 23:25:39

将其放在 single.php 文件的内部figure标签中

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

Put this inside figure tag of your single.php file

$image_caption = get_post(get_post_thumbnail_id())->post_excerpt;
if(!empty($image_caption)) { 
    echo '<figcaption itemprop="caption">' . $image_caption . '</figcaption>'; 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文