WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running this query which pulls all of the images attached to a particular post and outputs them into a slideshow (See example here - http://powers.deanelliott.me/property/1428-elm-street/)

Is there a way that I can directly output a link (So that the larger image gets displayed in a lightbox) into this query as adding link tags doesn't seem to work

<?php $args = array('numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => $post->ID); ?>
    <?php if ( $photos = get_posts($args) ) : ?>
        <?php foreach ( $photos as $photo ) : ?>
            <?php echo wp_get_attachment_image($photo->ID,'thumbnail'); ?>
        <?php endforeach; ?>
    <?php endif; ?>
share|improve this question
up vote 1 down vote accepted

I think you can use the_attachment_link or wp_get_attachment_link.



the_attachment_link( $photo->ID, false, false, true );
share|improve this answer
How would I include that in the original query though without having to use <a href="#"></a> which is where the problem lies – Dean Elliott Dec 14 '11 at 10:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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