我试图在引导式旋转木马中呼出我的图像标题。我已经设法让我的图像显示出来,但无法显示我的字幕。我尝试使用wp\\u get\\u attachment\\u元数据,但没有任何结果。
这是我正在使用的代码。
<?php
$args = array(
\'post_type\' => \'attachment\',
\'orderby\' => \'menu_order\',
\'order\' => ASC,
\'numberposts\' => -1,
\'post_status\' => null,
\'post_parent\' => $post->ID,
\'exclude\' => get_post_thumbnail_id()
);
$attachments = get_posts($args);
?>
<!-- Wrapper for slides -->
<!-- Wrapper for slides -->
<div class="carousel-inner">
<?php $i=0; foreach ($attachments as $attachment) { $imageInfo = wp_get_attachment_image_src($attachment->ID, \'full\'); $imageCap = wp_get_attachment_metadata($attachment->ID) ?>
<div class="item <?php if ($i == 0) { echo \'active\'; } ?> "> <img src="<?php echo $imageInfo[0]; ?>"/>
<div class="carousel-caption">
<h4><?php echo $imageCap->caption;?></h4>
</div>
</div>
<?php $i++; } ?>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
</div>
</div>
最合适的回答,由SO网友:DINESH BHIMANI 整理而成
检索图像的标题正确格式为
<?php $post_thumbnail_id = get_post_thumbnail_id( $post_id ); ?>
<?php
function wp_get_attachment( $attachment_id ) {
$attachment = get_post( $attachment_id );
return array(
\'alt\' => get_post_meta( $attachment->ID, \'_wp_attachment_image_alt\', true ),
\'caption\' => $attachment->post_excerpt,
\'description\' => $attachment->post_content,
\'href\' => get_permalink( $attachment->ID ),
\'src\' => $attachment->guid,
\'title\' => $attachment->post_title
);
}
$at= wp_get_attachment($post_thumbnail_id);
print_r($at);//show array of all image detail like title , caption etc
?>