ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Random Image Viewer

July 26, 2011 2:15pm

Subscribe [2]
  • #1 / Jul 26, 2011 2:15pm

    TrigFuller

    1 posts

    Hi,

    I’m very new to EE and I have been asked by a friend as a favour to implement something on his site. I’ve not used EE before and have to use whats there. EE version 1.x

    Currently he has one weblog called random where he sticks random images.

    On the site he has a panel where it random picks an image from that blog and displays it using this code

    {exp:weblog:entries weblog="random" orderby="random" sort="desc" limit="1" disable="member_data|trackbacks"}
      <div class=“random”>{rand_image}</div>
    {/exp:weblog:entries}

    What he wants is for people to be able to click on the image and it to change to another random image from that set.

    I’m used to fiddling around with php and flash so I’d know how to do it if I was using those but it needs to not use flash. I’m just wondering what my starting point should be. I’m guessing it’s some kind of jquery thing, but as I don’t do this professionally I don’t know much javascript.

    I would appreciate any pointers as to how to achieve this.

    Thanks.

    Trig

  • #2 / Jul 27, 2011 10:32am

    TrigFuller

    1 posts

    Hi,

    I worked out how to get it to do what I wanted.

    Used an external php file to create an javascript array of the images in the correct folder. Basically used the php found here with a slight alteration to add the full image path.

    http://www.javascriptkit.com/script/script2/phpviewer/

    added this script

    [removed]

    function changeImage(arrayX)
    {
    var randomnumber=Math.floor(Math.random()*arrayX.length);
    mainimage.src = arrayX[randomnumber];
    }
    [removed]

    and changed the code of the image display to

    {exp:weblog:entries weblog="random" orderby="random" sort="desc" limit="1" disable="member_data|trackbacks"}
      <div class=“random”>changeImage(picsarray)”]_{rand_image}</div>
    {/exp:weblog:entries}

    so it picks a random image from the blog then when clicked it loads another random one.

    Probably not the most elegant solution but it works.

    Trig

    EDIT: noticed that it removed the script bits at the start and end and replaced them with REMOVED, I’m guessing for security reasons.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases