Welcome, Guest. Please login or register.
Did you miss your activation email?
May 27, 2012, 02:25:47 AM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
155555 Posts in 21715 Topics by 7737 Members
Latest Member: gx-world
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Random Image snippet for use in the Template index.php  (Read 2654 times)
Bramus
Forum Team
*****
Offline Offline

Posts: 601


WWW
« on: April 16, 2007, 09:07:42 AM »

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.

Code:
<?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
« Last Edit: May 31, 2007, 09:08:00 PM by Bramus » Logged

BRAMUS Internet Services
janjoensen

Offline Offline

Posts: 7


« Reply #1 on: May 03, 2008, 07:40:37 PM »

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

Offline Offline

Posts: 495


« Reply #2 on: May 04, 2008, 02:11:41 AM »

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.
Logged
Danny

Offline Offline

Posts: 10


« Reply #3 on: July 28, 2008, 02:14:30 PM »

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.

Code:
<?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\"  />";
?>

Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!