How to make images display in a random order.
By Martin Taylor


See attached wpp file. It has three images down the page which will appear in a different sequence on each page load or refresh.

You need to make sure, when adding the images to the page, that:

1. You give them IDs such as 'pic_0', 'pic_1' ... in ascending order.
2. Your images are saved as (e.g) 'product0.jpg', 'product1.jpg' ... again in ascending order.
3. Use Web Export options on each image to make sure that WP uses your chosen name, and doesn't resample.

Then insert the following script, using Attach HTML, at the Page Body End marker.
<SCRIPT language="javascript">

var num_images = 3;

var temp = 0;
var newnumber = 0;

var picno = new Array(num_images - 1);

for (var i = 0; i < num_images; i++) {
picno[i] = i;
}

for (var i = 0; i < num_images; i++) {
newnumber = Math.floor((Math.random() * num_images));
temp = picno[i];
picno[i] = picno[newnumber];
picno[newnumber] = temp;
}

for (var i = 0; i < num_images; i++) {
document.getElementById("pic_"+i).src = "product"+picno[i]+".jpg";
}

</script>

In this script, set the number of images as appropriate at the top, and at the end, change the words "pic" and "product" if necessary to suit your own circumstances.

Hope this helps ... and works!

Martin

Serif forum link - random ordering of adverts?

Random image wpp file