WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.8 is now available!


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker

Your donations will help to:

  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!

You can donate by clicking on the button below.


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Random Image snippet for use in the Template index.php
  • Print
Pages: [1]   Go Down

Author Topic: Random Image snippet for use in the Template index.php  (Read 10288 times)

Offline Bramus

  • Posts: 608
  • Gender: Male
    • BRAMUS Internet Services
Random Image snippet for use in the Template index.php
« on: April 16, 2007, 10: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: [Select]
<?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, 10:08:00 PM by Bramus »
Logged
BRAMUS Internet Services

janjoensen

  • Guest
Re: Random Image snippet for use in the Template index.php
« Reply #1 on: May 03, 2008, 08:40:37 PM »
How can I get this with out border and automatic random?
Logged

Offline marathoner

  • Posts: 495
Re: Random Image snippet for use in the Template index.php
« Reply #2 on: May 04, 2008, 03: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

  • Guest
Re: Random Image snippet for use in the Template index.php
« Reply #3 on: July 28, 2008, 03: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: [Select]
<?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

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Random Image snippet for use in the Template index.php
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2