Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Jsl
    Jsl is offline
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Random image generator (sorta) WP

    Hello, (first post, most likely in the wrong place..but,)

    Im hoping someone can help explain the code and implementation, or point me in the right direction. Lets say i would like to have a particular wordpress page created, and on this page is a single container that will randomly generate/pull an image from a folder in my root or within my media uploads. Think iChing or Fortune Telling app. There would be a specific number of labeled images in a folder, and when a button is selected.. an image appears. Recycling the page each time to get a new image is not an option.

    If you want to get really fancy, how about adding a proper transition from start to image, and then back again.

    Anyhow, thanks in advance for any help! :] please do lemme know if more info would help..

  • #2
    New Coder
    Join Date
    Aug 2011
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would suggest posting this in the PHP or JavaScript section. From my own experience, PHP and JavaScript are your best bet to make a page that loads images randomly from an external source on the server.

  • #3
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by Jsl View Post
    Hello, (first post, most likely in the wrong place..but,)

    Im hoping someone can help explain the code and implementation, or point me in the right direction. Lets say i would like to have a particular wordpress page created, and on this page is a single container that will randomly generate/pull an image from a folder in my root or within my media uploads. Think iChing or Fortune Telling app. There would be a specific number of labeled images in a folder, and when a button is selected.. an image appears. Recycling the page each time to get a new image is not an option.

    If you want to get really fancy, how about adding a proper transition from start to image, and then back again.

    Anyhow, thanks in advance for any help! :] please do lemme know if more info would help..
    Quote Originally Posted by MrConman View Post
    I would suggest posting this in the PHP or JavaScript section. From my own experience, PHP and JavaScript are your best bet to make a page that loads images randomly from an external source on the server.
    Javascript is only needed for your last bit about 'getting fancy'. Javascript, in my opinion, should be reserved for luxury features only - nothing to do with the running of the site. My reasoning - javascript is executed client side leaving it very much open to malicious user manipulation.

    In terms of the PHP, if you're wanting a random image that, once generated, doesn't change for the person then you could use sessions or cookies (I would use a cookie). The function glob() returns an array of directories and files matching a pattern. So, using that array you would just need to random an index, save that index to a cookie. Your page would check for the cookie - if it exists, use the value to display the image index in glob() and if it doesn't, generate an index, save to cookie and then use that in the glob() generated array.

  • #4
    Jsl
    Jsl is offline
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks guys, much appreciated..

    The image can change, and should change back to the original 'opening/welcome image' if a user leaves the page or refreshes.. that's no big deal. i may have been a bit cryptic (my bad) most of the 'random anything' plugins i have found for WP rely on auto transitions or refreshing to generate another image.. i need a box, with a set opening image, and a button to pull 1 of 64 images from a folder, truly random though. Pretty much just need a button controlled oracle with 64 possibilities.

    Now i simply need someone to write it ?$? :]

    Thanks again!

  • #5
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by Jsl View Post
    Thanks guys, much appreciated..

    The image can change, and should change back to the original 'opening/welcome image' if a user leaves the page or refreshes.. that's no big deal. i may have been a bit cryptic (my bad) most of the 'random anything' plugins i have found for WP rely on auto transitions or refreshing to generate another image.. i need a box, with a set opening image, and a button to pull 1 of 64 images from a folder, truly random though. Pretty much just need a button controlled oracle with 64 possibilities.

    Now i simply need someone to write it ?$? :]

    Thanks again!
    Now that you've described your problem, it's a javascript solution you require . Or rather, JS will give you a smoother result as it's an image animator. You should take your question there (I do know a bit of JS but not enough to be confident enough to try a solution).


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •