Advertisement
firoze

Images changeing by every re-loading the browser

Jul 27th, 2015
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. // Images changeing by every re-loading the browser
  2.  
  3. <?php
  4. // Change to the type of files to use eg. .jpg or .gif or .png
  5. $file_type = ".jpg";
  6.  
  7. // Change to the location of the folder containing the images
  8. $image_folder = "images"; // this is img folder name
  9.  
  10. // write the start and end number of image.
  11. $random = mt_rand(1, 5); // here 1, 2 image serial number and 5 is serial number 5 that mean there are 5 images
  12.  
  13. $image_name = $random . $file_type;
  14.  
  15. // only img
  16. echo '<img src="'.get_template_directory_uri().'/'.$image_folder.'/'.$image_name.'" alt="'.$image_name.'" />';
  17.  
  18.  
  19. // set background images
  20. echo
  21. '
  22. <style type="text/css">
  23. .services_area{background:url("'.get_template_directory_uri().'/'.$image_folder.'/'.$image_name.'") no-repeat scroll 0 0;background-size:cover;}
  24. </style>
  25. ';
  26. ?>
  27.  
  28. <!-- use image out of root php code only img -->
  29. <?php echo '<img src="'.get_template_directory_uri().'/'.$image_folder.'/'.$image_name.'" alt="'.$image_name.'" />';?>
  30.  
  31. <!-- set background images out of root php code -->
  32. <?php
  33. echo
  34. '
  35. <style type="text/css">
  36. body{background:url("'.get_template_directory_uri().'/'.$image_folder.'/'.$image_name.'") no-repeat scroll 0 0;background-size:cover;}
  37. </style>
  38. ';
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement