J'essaie de faire écho à mes légendes d'images dans un carrousel Bootstrap. J'ai réussi à faire afficher mes images mais je n'ai pas pu afficher mes légendes. J'ai essayé d'utiliser wp_get_attachment_metadata, mais rien n'a été renvoyé.
Voici le code que j’utilise.
<?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>
Récupérer la légende du format d'image correct est
<?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
?>