Title: Image Slideshow for posts
Last modified: August 19, 2016

---

# Image Slideshow for posts

 *  [triphys](https://wordpress.org/support/users/triphys/)
 * (@triphys)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/image-slideshow-for-posts/)
 * Hello
 * I’m trying to get a slideshow working for my wordpress blog. This is how I would
   like it to work:
 * I have custom fields on the posts where I post a project, like if I have have
   three different images for my slideshow there is “image_1, image_2 and image_3”
   defined as custom fields.
    Sometimes tho I may only have one image defined.
 * So the thing is, I found this great jquery slideshow script which I’m running
   and works fine. Only problem is that I have to define in the single.php code 
   how many pictures to show, and that’s different from post to post, so I need 
   an algorithm to check for how many images I have attached to my post.
 * My code for the slides on single.php looks like this now:
 *     ```
       <div id="featured">
       <img src="<?php echo get_post_meta($post->ID, "image_1", true);?>" alt="1" />
       <img src="<?php echo get_post_meta($post->ID, "image_2", true);?>" alt="2" />
       <img src="<?php echo get_post_meta($post->ID, "image_3", true);?>"  alt="3" />
       </div>
       ```
   
 * So I found this bit of code which I tried but can’t get to work.
 *     ```
       <?php
       $number_of_images = 0;
       for ($i=1; $i<=10; $i++) {
       $image = get_post_meta($post->ID, 'image_'.$i, true);
       if ($image && $i == 1) {
       echo "<img src='".$image."' id='image_".$i."'>";
       $number_of_image++;
       } elseif ($image) {
       echo "<img src='".$image."' id='image_".$i."' style='display:none;'>";
       $number_of_images++;
       }
       }
       ?>
       ```
   
 * Right now I have removed the php code and is just running the default <div>. 
   It looks like this right now: [Example](http://www.triphys.com/2010/10/birthday-gift/)
 * Would be great if someone could help me! Thanks in advance!

The topic ‘Image Slideshow for posts’ is closed to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [triphys](https://wordpress.org/support/users/triphys/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/image-slideshow-for-posts/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
