• I’m trying to display an image gallery which contains pictures of my company’s leadership. When each image is clicked it should display their bios under the thumbnail gallery (which is about 5-columns wide and 3 rows high).

    Based on the Codex page over here, I have managed to get the thumbnails to display. However the Image Description is only appearing for the last image that is arrayed under my $args.

    How do I get the image description to appear only when the mouse hovers over the image, or when it clicks the thumbnail?

    Any help would be greatly appreciated!

    Here is what I have been trying to do:

    <?php $query2 = new WP_Query( 'post_type=page&page_id=40' );?>
    
    <?php if ($query2->have_posts()) : while($query2->have_posts()) : $query2->the_post();
      $args = array(
       'post_type' => 'attachment',
       'numberposts' => -1,
       'post_status' => null,
       'post_parent' => $post->ID
      );
    
      $attachments = get_posts( $args );
         if ( $attachments ) {
            foreach ( $attachments as $attachment ) {
               echo '<ul><li>';
               echo wp_get_attachment_image( $attachment->ID, 'full' );
    		   echo '</li><li>';
               echo apply_filters( 'the_description', $attachment->post_content);
               echo '</li></ul>';
              }
         }
    
     endwhile; endif; ?>

  • The topic ‘Image descriptions – appear only when Image is hovered over or clicked on?’ is closed to new replies.