echo image caption

时间:2014-10-15 作者:Ben Hathaway

我试图在引导式旋转木马中呼出我的图像标题。我已经设法让我的图像显示出来,但无法显示我的字幕。我尝试使用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>

1 个回复
最合适的回答,由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

?>

结束

相关推荐

Removing blog page images

我有我的blog page here 然而,在我创建的一个网站上,我不太明白在哪里可以找到代码来去除我孩子主题上的图像。我使用的是2010年的代码,我已经设置了自己的博客模板页面,但它不起作用,所以我显然编辑了错误的文件。所以不是循环。php我想要编辑的文件,以便在主博客页面上删除这些图像?<?php /* How to display all other posts. */ ?> <?php else : ?> <div i