treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Assign Classes to Gallery Images

  • So, I'm using the WP Simple Galleries plugin and I was wondering if it's possible to modify the code to say, if the gallery say has 4 or more images then assign an array of unique classes to each of the images like so:

      <img src ="image.jpg" class="1">
      <img src ="image.jpg" class="2">
      <img src ="image.jpg" class="3">
      <img src ="image.jpg" class="4">
    

    Here's the PHP that returns the gallery:

      private function thumb($id, $post_id) {
          $image = wp_get_attachment_image_src($id, 'wpsimplegallery_thumb', true);
          $info = get_posts(array('p' => $id, 'post_type' => 'attachment'));
          return '<li><a href="' . wp_get_attachment_url($id) . '" title="' . $info[0]->post_title . '" rel="wpsimplegallery_group_' . $post_id . '"><img src="' . $image[0] . '" width="' . $image[1] . '" height="' . $image[2] . '" /></a></li>';
      }
    

    And here's a link to the complete wp-simple-gallery.php file.

    I'm still trying to grasp PHP, and I'm sure this can this be done using arrays and an if statement of some sort. If anyone could help lead me in the right direction it would be much appreciated.

    Thanks in advance.