Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to have the post thumbnail image link to a gallery of post attachements displayed using pirobox. This is the code i use:

 <?php if(has_post_thumbnail()){?>
 <div class="post-single-images left">
 <a href="<?php echo wp_get_attachment_url( get_post_thumbnail_id() )?>" class="pirobox_gall" title="<?php the_title(); ?>" rel="gallery">
 <?php the_post_thumbnail('single'); ?></a>
 </div><?php }?>

  <?php
    $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image' ) );
    foreach ( $attachments as $attachment_id => $attachment ) {
    echo '<a href="';
    echo '' . wp_get_attachment_url( $attachment_id ) . '" class="pirobox_gall" title="<?php the_title(); ?>" rel="gallery">';
    echo '<img style="display:none;" src="' . wp_get_attachment_url( $attachment_id ) . '" >'; 
    } ?>

I'm getting the post thumbnail image (first in attachements) repeated five or more times in the pirobox slideshow - see here: http://anarita.me/protocolar/portfolios/inauguracao-do-cinema-city-alvalade/ -, and can't understand why.

Can someone help me?

Thank you, Ana Rita

share|improve this question
    
Looking at Pirobox examples I see they're wrapping the images in a <ul><li><a><img></a></li></ul> structure, try that... –  brasofilo Jun 22 '12 at 15:58
    
Well, there was a </a> missing at the end, on my code. I'll post the working code below. –  AnaRita Jun 23 '12 at 17:35
add comment

1 Answer

There was a </a> tag missing at the end of the code. I also added an exclusion of the thumbnail id from the get_children query. It's working now.

<a href="<?php echo wp_get_attachment_url( get_post_thumbnail_id() )?>" class="pirobox " title="<?php the_title(); ?>" rel="gallery">
<?php the_post_thumbnail('single'); ?>
</a>

<?php $thumbnail = get_post_thumbnail_id($post->ID);
      $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'exclude' => $thumbnail) );
         foreach ( $attachments as $attachment_id => $attachment ) {
           echo '<a href="';
           echo '' . wp_get_attachment_url( $attachment_id ) . '" class="pirobox " title="<?php the_title(); ?>" rel="gallery">';
           echo '<img style="display:none;" src="' . wp_get_attachment_url( $attachment_id ) . '" ></a>'; } ?>
share|improve this answer
add comment

Your Answer

 
discard

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.