wordpress Get Image Description for attached images

I’m trying to make a post split in 2 columns. The first column is going to be any image attached to the post, and the right column will be the_content() (excluding the images).

So as of now I have no problem pulling all the images. However – I can’t seem to get the image caption or title or description.

Read More

Heres my code: (this is going inside a page)

<?php if ( $images = get_posts(array(
        'post_parent' => $post->ID,
        'post_type' => 'attachment',
        'numberposts' => -1,
        'orderby'        => 'title',
        'order'           => 'ASC',
        'post_mime_type' => 'image',
    )))
    {
        foreach( $images as $image ) {
            $attachmenturl = wp_get_attachment_url($image->ID);
            $attachmentimage = wp_get_attachment_image_src( $image->ID, full );
            $imageDescription = apply_filters( 'the_description' , $image->post_content );
            $imageTitle = apply_filters( 'the_title' , $image->post_title );
            $i++;
            if (!empty($imageTitle)) {
                echo '<div class="client-img-item ci-'.$count++.'"><img src="' . $attachmentimage[0] . '" alt="'.$imageTitle.'"  /> <div class="CAPS client-img-caption"><span class="red arrow-lrg">»</span> '.$imageDescription.'</div></div><div class="sml-dots"></div>';
} else { echo '<img src="' . $attachmentimage[0] . '" alt="" />' ; }
        }
    } else {
        echo 'No Image Found';
    }?>

Related posts

Leave a Reply

1 comment

  1. Does this help keeping the original formatting : caps and whitespaces?

    apply_filters( 'the_description' , $image->post_content );
    

    When targetting my featutered image to a nextgen gallery the description tekst is changed : caps changes (uppercase/lowercase etc).. whitespaces and removing dots at the end etc…
    Anyone?