Wordpress:从媒体项中提取alt文本

时间:2013-08-13 17:06:41

标签: php wordpress lightbox

我正在设计图片博客,但遇到了一些问题。我能够拉出灯箱媒体项目的“标题”区域,但我无法拉动“alt”区域或“描述”区域。有什么想法吗?

<?php if($attachment->post_excerpt): ?>alt="<?php echo $attachment->post_excerpt; ?>"<?php endif; ?>

(这就是我用来从媒体项标题区域拉出来的)

<?php $image = wp_get_attachment_image_src($attachment->ID, 'full'); ?>
                    <li><a href="<?php echo $image[0]; ?>" rel="prettyPhoto[gallery]" class="hover-gradient" title="untitled"><p style="display:none;"><?php if($attachment->post_excerpt): ?><?php echo $attachment->post_excerpt; ?><?php endif; ?></p><img src="<?php echo $thumbnail[0]; ?>" alt="gallery-blog" /></a></li>
                    <?php endforeach; endif; ?>

(这是主页拇指的扩展代码)

我基本上正在寻找替代alt =“gallery-blog”区域的东西,以便它将从媒体页面显示媒体项目alt文本

2 个答案:

答案 0 :(得分:4)

您可以获得媒体标题,标题和说明,如下所示

$alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
$image_title = $attachment->post_title;
$caption = $attachment->post_excerpt;
$description = $image->post_content;

答案 1 :(得分:2)

wp_get_attachment_image();函数回显有关图片的所有信息,包括altsrcwidthheightclass < / p>

Codex