WordPress.org

Ready to get started?Download WordPress

Forums

Image Slideshow for posts (1 post)

  1. triphys
    Member
    Posted 3 years ago #

    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

    Would be great if someone could help me! Thanks in advance!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.