Ok enough talking loser like me today we back on topic, now right now I want talk about images and radomizer, sometimes in some case we want rotate our image to make our blog look unique and fresh everytime people came to our site, but how we make image showing random each time they open it?
Ok lets try, first we need the ingredient LOL, I mean we need prepare all thing
- image collection, and rename it to 1.jpg, 2.jpg, 3.jpg, 4.jpg, and remember all extension must same (all jpg, or all gif, or all png)
- folder, create folder for example imgrotator folder
- the code (I will show later)
Ok now put all images on imgrotator folder that you already create, and on the page you want to put the rotator images, paste this this code
<img src="/path/to/<?php echo rand(1,n);?>.jpg" alt="Random Image" />
See this part /path/to/ change to the path of image rotator folder, in this case folder imgrotator and for the rand(1,n); you just put total of image, in this case I put 4 image, so we change the “n” to 4 and became like this rand(1,4); and now your image rotator ready to upload… the finish code for this case is like this
<img src="/imgrotator/<?php echo rand(1,4);?>.jpg" alt="Random Image" />
Now try yours good luck..
nb: Ill try to give another way to use this as background rotator for your site header on next post, just wait