• hey ive tried a lot of things here but cant get this working..
    i have an image gallery being generated by a the wpshower portfolium theme, basically i want to show the img decription under the image, before the gallery nav.
    First probem – i cant access the description, second if i manage to pull some content, it appears as an extra attachment in the loop.

    here is the default gallery loop from the theme:

    `<?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);
    if ( $attachments ):
    foreach ( $attachments as $attachment ):
    echo wp_get_attachment_image($attachment->ID, ‘full’);
    endforeach;
    endif;
    ?>`

    Any help appreciated – seems like it shouldbe simple but i cant seem to get the solution 🙁 !

    http://lucybenson.net/2012/portfolio/projections-from-jupiter/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter lbens

    (@lbens)

    ps all info about getting attachment description seems to say use the_content() but that just gives me the actual post content… i must be missing something. cheers 🙂

    foreach ( $attachments as $attachment ):
    echo wp_get_attachment_image($attachment->ID, 'full');
    $description = $attachment->post_content;
    if ($description):
    echo $description;
    endif;
    endforeach;
    Thread Starter lbens

    (@lbens)

    hey – that certainly brings up the description – thanks!

    but any idea how to make this appear underneath the image, so that it changes with the image as you click through the gallery??

    at the moment, the text appears on top of the image and also breaks the div somehow (see link above – click on the images to see the text)

    if i try to put a line break or seperating div in your code between image and description, this linebreak appears as an attachments item in the gallery.

    thanks so much! 🙂

    Yes, it must be styled, try
    echo '<div>' . $description . '</div>';
    but tested it now on similar gallery, it shows description on a separate blank turn of the slideshow. It seems that js getting <div> as a slideshow element :/

    Thread Starter lbens

    (@lbens)

    yup that’s my problem too…. hrmmm…. is it possible calling it in another way than echo would make a difference? I mean, it should be possible to do other things within a for loop.. not just this inbuilt behaviour.

    Working Callbacks example here http://jquery.malsup.com/cycle/int2.html
    I’ll try to glue it, but not today 🙂

    Actually I’am using the cycle script for slideshow with descriptions, but it has different <div> structure. I’ll test it with a paging element.

    Thread Starter lbens

    (@lbens)

    oh cool 🙂 i cant see where to begin with this cycle script – big blocks of unformatted code.. its too much for me!

    Found it out 🙂
    Image and description must be inside one common div with class (.slide here), so it will be an element of a slide show. And both img/desc you can optionally enclose in self div’s for styling.

    foreach ( $attachments as $attachment ):
        echo '<div class="slide">';
        echo '<div class="slide-image">';
        echo wp_get_attachment_image($attachment->ID, 'full');
        echo '</div>';
        $description = $attachment->post_content;
        if ($description):
            echo '<div class="slide-description">' . $description . '</div>';
        endif;
        echo '</div>';
    endforeach;

    So, it doesn’t need mentioned callbacks.

    Сorrection: <div> without a class is enough.
    In nearest future I’ll read theoretical articles on your site 🙂

    Thread Starter lbens

    (@lbens)

    AMAZING!!! works perfectly! I didnt know you could echo css tags like this. Neat solution, thanks so much 🙂

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘get attachment description – for gallery’ is closed to new replies.