Welcome, Guest. Please login or register.
Did you miss your activation email?
May 26, 2012, 05:51:00 PM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
155545 Posts in 21714 Topics by 7736 Members
Latest Member: chris85
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Random Image with link to page  (Read 426 times)
sky writer

Offline Offline

Posts: 285



« on: May 14, 2011, 07:30:04 PM »

I've searched and can't find this functionality.

I have a page that I want to put several images on.  Each image will be a random image from a separate media folder.  I know I can do all this with the random image snippet in a code section.  The catch is, I want these images to be links to specific pages.  Can this be done within a code section as well?  I don't need the whole process to be automated, just the random selection of image.  I am fine with manually entering in the wblink direction to the correct pages.

Thanks in advance for your help.
Logged
Bug

Offline Offline

Posts: 188


« Reply #1 on: May 14, 2011, 08:26:25 PM »

I would use members with in the loop an extra script to randomise the order of the members

This way you can add images ad ad a link to these images

It will need some creativity but it will work
Logged
Bug

Offline Offline

Posts: 188


« Reply #2 on: May 14, 2011, 09:35:27 PM »

Looked it up, I used members once to get it done,
Code:
Header:

<style type="text/css">

.jsclass body .randomcontent{ 
display: none;
}

</style>

<script type="text/javascript">


if (document.getElementById)
document.documentElement.className = 'jsclass'; //hide content for DOM capable browsers


var randomcontentdisplay={
divholders:new Object(),
masterclass: "randomcontent",

init:function(){
if (!document.getElementById)
return
var alldivs=document.getElementsByTagName("div")
var randomcontentsearch=new RegExp(this.masterclass+"\\s+(group\\d+)", "i") //check for CSS class="randomcontent groupX" (x=integer)
for (var i=0; i<alldivs.length; i++){
if (randomcontentsearch.test(alldivs[i].className)){
if (typeof this.divholders[RegExp.$1]=="undefined") //if array to hold this group of divs doesn't exist yet
this.divholders[RegExp.$1]=new Array() //create array first
this.divholders[RegExp.$1].push(alldivs[i]) //add this div to the array
}
}
this.showone()
},

showone:function(){
for (group in this.divholders){ //loop thru each array within object
var chosenOne=Math.floor(Math.random()*this.divholders[group].length) //randomly pick one entry from array
this.divholders[group][chosenOne].style.display="block" //display content corresponding to the chosen entry
}
}
}

</script>



-------------------------------------------------------------

Member:

<div class="randomcontent group1">
<table width="906" height="247" border="0" cellpadding="5" cellspacing="0" background="[PICTURE]">
  <tr>
    <td valign="top">
    
 
<div style="height:190px;width:890px;"><span class="bannerstyle3">[LONG1]</span></div>
<div style=" width:890px; height:20px; text-align:right;"><span class="bannerstyle4">[LINK]</span></div>
    
    </td>
    </tr>
</table>

</div>

-------------------------------------------------------------

Footer:

<script type="text/javascript">
randomcontentdisplay.init()
</script>
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!