Fork me on GitHub

Random Photo Retrieval  Bottom

  • Howdy all,

    I'm using the i-nuka theme on my site (http://nemo.compsoc.com/10k) and I was wondering, has anyone any thoughts on how to randomise the photos that are displayed on the topbar?

    ie, a snippet of jscript that selects 4 photos from the images directory.

    Thanks in advance for any help!

    Doyler
  • I'm not familiar with that theme, but I gather you would like to have a folder full of images that are randomly displayed each time the page is called. The easiest way to do that would be to embed a few lines of PHP code into the theme.html page to randomly chose each of four images (making sure they don't repeat).

    It a nifty idea for a theme.
  • Any Suggestions as to how the PHP code should go? I can do it in Java, but my PHP is somewhat.....Useless!

    Thanks
    Doyler
  • Here's something I did for a theme (place in the top of the themeheader) that pics from a predetermined list of pics:
    // Random header pic

    Code

    $header_array = array('header_aug.jpg','header_dec.jpg','header_feb.jpg','header_mar.jpg','header_nov.jpg','header_oct.jpg');
    srand((float)microtime()*1000000);
    shuffle($header_array);
    $header_pic = $header_array[0];

    Then just echo 'yourimagedirectory/'.$header_pic...

    --
    Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

    Cape Cod Travel Info...
  • worked perfect, thanks everyone!
  • Nate does good work!
  • Yes nice concept Nate, but remember the great thing about themes is the fact that graphics are reused across the entire site; if you put random images in it means that people will have to wait for them to load each time. I guess it wouldn't matter if they were small though :)

    regards

    --
    -Lobos
    Professional PHP Framework Services: Concept, Development and Deployment
  • Agreed. Its nifty idea to have a theme element that loads 4 or 5 small "family" pics, however.
  • True enough Lobos, but in all likelyhood, we'd only be talking about 20-30K max per pic, and where it is a limited amount of images, they'd get cached after just a few page views ;)

    --
    Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

    Cape Cod Travel Info...
  • Point taken :)

    --
    -Lobos
    Professional PHP Framework Services: Concept, Development and Deployment
  • I was writing a theme following Nate´s guidelines ( many, many thanks; I learned a lot from you ) and I needed to do the same thing with 8 small GIFs. I named them header1 to header8, and wrote this:

    Code

    <img src="header<?=mt_rand(1,8)?>.gif" width="50" height="50" alt="">

    I used mt_rand() because it´s four times faster than rand(), and also doesn´t need a seed feed.
  • Now *that's* clever!

    Ahhh... the student surpasses the master... :)

    --
    Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

    Cape Cod Travel Info...
  • Having used the ever wise nate's coding, the site has been running perfect, except for one thing. (Probably something that only bugs me!) Even though the photos to choose from is quite varied, every so often one or two of the photos are the same. Any ideas on how to code it so that if a photo is chosen, that photo is locked out for the rest of the randoms? If you know what I mean! icon_rolleyes
  • 0 users

This list is based on users active over the last 60 minutes.