Random Image snippet for use in the Template index.php

Danny

Thx 4 sharing your work Bramus!

I had a problem with sub-menus and/or multilanguage versions of websites.
Easy fix for it with the Template_dir function of wbb.

<?php
$total 
"6";
$file_type ".jpg";
$dir TEMPLATE_DIR// get template-dir 

$image_folder "img/random";

$start "1";
$random mt_rand($start$total);
$image_name $random $file_type;

$filename "$image_folder/$image_name";

print 
"<img src=\"$dir/$image_folder/$image_name\"  />";
?>



marathoner

Border is controlled via CSS. Just style the IMG tag, or whatever tag you are referring to, without a border.

I don't know what you mean by without automatic random since this is a random image snippet.

janjoensen

How can I get this with out border and automatic random?

Bramus

Since i was looking for the random image snippet for my site, and the one posted here
did not work in the index.php of my template i went searching for another. With some google job and php knowledge of myself i managed to modify an existing code and i did a test on my websites and it did work 100%!

Go to the page were you want your image, i assume some were in the index.php of your template folder. Paste the following code there.


<?php

// Total images that are in the folder set below
$total "11";

// The file type you want to use
$file_type ".jpg";

// The location of your random images
$image_folder "../media/random";

// No editing needed below this

$start "1";

$random mt_rand($start$total);

$image_name $random $file_type;

echo 
"<img src=\"$image_folder/$image_name\" alt=\"$image_name\" />";

?>



Remember to name your images as: 1.gif - 2.gif and so on, or 1.jpg - 2.jpg and so on.

You can also make a different php page like randomimage.php and use the include function, but i didn't test that.

Just using the code above in your index.php of your template should do the job.

Comments are always welcome!


Greetz BramuS
BRAMUS Internet Services