0

After getting my images through a metabox for a gallery post format I have the following code to show them on the post front end:

<?php

    if ( !empty( $images ) ) {
        foreach ( $images as $image ) {

           echo
               '<li class="animated fadeIn">',
                    '<figure>',
                         wp_get_attachment_image( $image, 'post-full-width' ),
                    '</figure>',
                '</li>';
        }
     }
?>

I am just wondering now how to show the images captions on the front end along with the images also.

0

You can add to figcaption on your front-end.

<?php

    if ( !empty( $images ) ) {
        foreach ( $images as $image ) {

           $image_post = get_post($image);
           $caption = $image_post->post_excerpt;

           echo
               '<li class="animated fadeIn">',
                    '<figure>',
                         wp_get_attachment_image( $image, 'post-full-width' ),
                         '<figcaption>', 
                               $caption, 
                         '</figcaption>',
                    '</figure>',
                '</li>';
        }
     }
?>
  • Sure did. You're the man!;) Thanks a lot. I have another couple of questions. Should I create new questions to ask those? One of them is Javascript, not sure if you would want to have at that one. – Madeirense Dec 30 '15 at 20:25
  • Thanks a lot dude. Here is one wordpress.stackexchange.com/questions/213321/… – Madeirense Dec 30 '15 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.