FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


question : how to display random image in main page?





engeland
Some sites have random pictures which correspond with their coppermine galleries or even 4images. Upon clicking, it directs to the gallery. How can i put this in my site's main page? Confused

please help
sciondestiny
I think I know what you mean, it is pretty simple if it is this:

you would have to write it like so:

Code:

[url="THE SITE LINK TO THE GALLERIES"]the link to the image!!![/url]
engeland
um...this is a url.
i meant picture.

ok, just an example which popped out of my mind. go to www.kirsten-dunst.org . you can see that her random image thumbnail changes upon every visit and once clicked, directs to the site's gallery.

how do i do exaclty that? Confused
LukeakaDanish
Eh...either you could do it by writing the pictures with javascript onload or, if you know any of this, you could make a php script (possibly the more intelligent and fast way of doing it)

If you dont know javascript i could write you one for a little frih$ payment Very Happy

Sorry for the blackmailing...Very Happy

Luke
engeland
LukeakaDanish wrote:
Eh...either you could do it by writing the pictures with javascript onload or, if you know any of this, you could make a php script (possibly the more intelligent and fast way of doing it)

If you dont know javascript i could write you one for a little frih$ payment Very Happy

Sorry for the blackmailing...Very Happy

Luke


hwoa, dude i saw your site and that is a very impressive navigation bar! is that all java?

as for the random pic. Is java the only way you could offer? coz i'd pay for php. I think its how its really supposed to be Confused
LukeakaDanish
engeland wrote:
LukeakaDanish wrote:
Eh...either you could do it by writing the pictures with javascript onload or, if you know any of this, you could make a php script (possibly the more intelligent and fast way of doing it)

If you dont know javascript i could write you one for a little frih$ payment Very Happy

Sorry for the blackmailing...Very Happy

Luke


hwoa, dude i saw your site and that is a very impressive navigation bar! is that all java?

as for the random pic. Is java the only way you could offer? coz i'd pay for php. I think its how its really supposed to be Confused


It's not java, but javascript (sounds similar but there's a hell of a difference)

Im not too good with PHP, but i could try doing it for you anyway Very Happy

Just to make sure i know exactly what you want:

    Display random images next to each other in a line

    Have the images link to their galleries
Omax
Put this in <HEAD>
Code:

<SCRIPT LANGUAGE="javascript">
<!--This is one of many scripts which are available at:     *---
//--http://www.JavaScript.nu/javascript                     *---
//--This script is FREE, but you MUST let these lines       *---
//--remain if you use this script.                          *---
function visa_bild()
{

//***---Here you type what pictures you want, you can have as many you like
bild=new Array("0.gif","1.gif","2.gif","3.gif","4.gif","5.gif")

visa_bilden=bild[Math.floor(Math.random()*bild.length)]
visa_bilden="<IMG SRC=\""+visa_bilden+"\">"
return visa_bilden
}
//-->
</SCRIPT>



Type this in <BODY>
Code:

<SCRIPT LANGUAGE="javascript">
<!--
document.write(visa_bild())
//-->
</SCRIPT>


Then I'm not sure, if you could put a
Code:
<a href="
over the javascript in BODY
LukeakaDanish
Then I'm not sure, if you could put a
Code:
<a href="
over the javascript in BODY[/quote]

Yea you cold do...but if you want dynamic links you would need to do them with javascript aswell...

There is a problem with that script aswel...it might end up writing the same image twice...

However i do recomend you using javascript rather than PHP, simply for the simplicity and "ease of editing"

I'm rewriting it to do the linking now...

Luke
LukeakaDanish
Code:

<html>

<head>

<script language="javascript" type="text/javascript">

<!--

images = new Array('graphics/bg.png'); //write paths of images inside '', and seperated by ,
links = new Array('index.html'); //write links inside '', and seperated by , . Item number one in this "array" coresponds to item number 1 in the above array etc.

//images will have class="randomImage" set. if you dont want borders, remember to set "border-width: 0px;" with CSS


usedImages = new Array(); //dont change this, or anything below, unless you know what your doing...

madeImage = false;

function writeImage() {
   do {
      imgNumber = Math.floor(Math.random()*images.length);
      if (isntUsed(imgNumber)) {
         writeString = '<a href="' + links[imgNumber] + '"><img src="' + images[imgNumber] + '" class="randomImage"></a>'
         madeImage = true;
      }
   }
   while(!madeImage);   
   return writeString;
}

function isntUsed(theImg) {
   if (usedImages.length != 0) {
      i = 0;
      do {
         if (usedImages[i] == theImg) {
            return false;
         }
         i++;
      }
      while(i<images.length);
   }
   return true;
}

-->

</script>

</head>

<body>

<script language="javascript" type="text/javascript">

<!--

document.write(writeImage());

-->

</script>

</body>

</html>


No need to thank me...

Very Happy

Luke
Related topics
Text color of main page
Broken link on main page
Better Browser Support for Main Page
My main page doesnt load
Random Image
Display random image on foreign site
Changed my main page....not showing
pulling data out of a database and putting it on main page
xoops main page
JScript Sliding Text Areas ( Adobe's main page sample)
Login link in the main page itself
random image code?
I want to output an img url from a random image script
IE8 not allowing new random image on each page (PHP and CSS)
Reply to topic    Frihost Forum Index -> Webmaster and Internet -> Design Tips

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.