Status
Not open for further replies.

victor_rambo

हॉर्न ओके प्लीज़
There is actually no need to modify any WP files for that. You can do that with javascript too, but I will discuss here how its done with PHP:

There is actually no need to modify any WP files for that. You can do that with javascript too, but I will discuss here how its done with PHP:
PHP:
//put names of all images you want to rotate randomly
$image_set=array("img1.jpg","img2.jpg","img3.jpg","img4.jpg");

//now select any one random image
$randomly_selected_image=$image_set[array_rand($image_set,1)];

//now fetch the image and store it in a string
$image=file_get_contents("images/$randomly_selected_image");

//send a header to the browser telling it that we are now sending an image
header("Content-type: image/jpg");

//now send the image. 
echo $image;

/*
Because we informed the browser earlier that we are sending an image, it could parse that string as an image.
Else it gets confused and parses it as plain text which looks horrible(with all question marks and rhombuses and weird characters-like the one when fonts are missing!)
*/

Now you can save this file as randomimage.php on yourserver. The HTML markup for your posts would be
Code:
<img src="randomimage.php" alt="random image" title="This image has been generated randomly and will change on refreshing">
Thats how simple it is!
 
Last edited:
Status
Not open for further replies.
Top Bottom