Add a custom image rotator


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function custom_image_rotator() {
  2. echo '<div class="image_box">';
  3. $rotator_dir = opendir(THESIS_ROTATOR);
  4. while (($file = readdir($rotator_dir)) !== false) {
  5. $haystack = strtolower($file);
  6. if (strpos($haystack, '.jpg') || strpos($haystack, '.jpeg') || strpos($haystack, '.png') || strpos($haystack, '.gif')) {
  7. $images[$file]['url'] = THESIS_ROTATOR_FOLDER . '/' . $file;
  8. $image_path = THESIS_ROTATOR . '/' . $file;
  9. $image_size = getimagesize($image_path);
  10. $images[$file]['width'] = $image_size[0];
  11. $images[$file]['height'] = $image_size[1];
  12.  
  13. if (thesis_get_image_size_class($image_size[0], $image_size[1]))
  14. $images[$file]['class'] = 'class="' . thesis_get_image_size_class($image_size[0], $image_size[1]) . '" ';
  15. }
  16. }
  17.  
  18. if ($images)
  19. $random_image = array_rand($images);
  20. $image_alt_tags = thesis_get_option('image_alt_tags');
  21. $image_link_urls = thesis_get_option('image_link_urls');
  22.  
  23. if ($image_alt_tags[$random_image])
  24. $images[$random_image]['alt'] = $image_alt_tags[$random_image];
  25. else
  26. $images[$random_image]['alt'] = $random_image;
  27.  
  28. $img = '<img ' . $images[$random_image]['class'] . 'src="' . $images[$random_image]['url'] . '" alt="' . $images[$random_image]['alt'] . '" />';
  29.  
  30. if ($image_link_urls[$random_image]) {
  31. $link_before = '<a href="' . $image_link_urls[$random_image] . '">';
  32. $link_after = '</a>' . "\n";
  33. }
  34. else
  35. $img .= "\n";
  36.  
  37. echo $link_before . $img . $link_after . '</div>';
  38. }
  39. add_action('thesis_hook_after_multimedia_box', 'custom_image_rotator');

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.