Return to Snippet

Revision: 15836
at July 18, 2009 18:48 by fabi


Initial Code
function custom_image_rotator() {
echo '<div class="image_box">';
    $rotator_dir = opendir(THESIS_ROTATOR);
    while (($file = readdir($rotator_dir)) !== false) {
        $haystack = strtolower($file);
        if (strpos($haystack, '.jpg') || strpos($haystack, '.jpeg') || strpos($haystack, '.png') || strpos($haystack, '.gif'))  {
            $images[$file]['url'] = THESIS_ROTATOR_FOLDER . '/' . $file;
            $image_path = THESIS_ROTATOR . '/' . $file;
            $image_size = getimagesize($image_path);
            $images[$file]['width'] = $image_size[0];
            $images[$file]['height'] = $image_size[1];
            
            if (thesis_get_image_size_class($image_size[0], $image_size[1]))
                $images[$file]['class'] = 'class="' . thesis_get_image_size_class($image_size[0], $image_size[1]) . '" ';
        }
    }
    
    if ($images)
        $random_image = array_rand($images);
    $image_alt_tags = thesis_get_option('image_alt_tags');
    $image_link_urls = thesis_get_option('image_link_urls');
    
    if ($image_alt_tags[$random_image])
        $images[$random_image]['alt'] = $image_alt_tags[$random_image];
    else
        $images[$random_image]['alt'] = $random_image;
        
    $img = '<img ' . $images[$random_image]['class'] . 'src="' . $images[$random_image]['url'] . '" alt="' . $images[$random_image]['alt'] . '" />';
    
    if ($image_link_urls[$random_image]) {
        $link_before = '<a href="' . $image_link_urls[$random_image] . '">';
        $link_after = '</a>' . "\n";
    }
    else
        $img .= "\n";
    
    echo $link_before . $img . $link_after . '</div>';
}
add_action('thesis_hook_after_multimedia_box', 'custom_image_rotator');

Initial URL

                                

Initial Description

                                

Initial Title
Add a custom  image rotator

Initial Tags
image

Initial Language
PHP