Author Topic: Random Link  (Read 1763 times)

Offline SurfSmarter

  • Sr Member
  • Posts: 516
    • View Profile
Random Link
« on: March 30, 2011, 02:44:39 PM »
Mark et al,

I appear to be getting thick in my old age, and i'm not referring just to the waistline, lol. So I must defer to anyone whose age isn't affecting them to the same degree...

How can I set random/rotated link(s) to appear in the footer of a site?

The link(s) would be called from a single simple source file (maybe .txt or html) hosted on a separate server.

Basically use would be as a "sponsored by theme" but each 'fresh' load would pull a different click-able text link from the master list.

Any insight is alway appreciated

John



Offline Mark Austin

  • Admin
  • Posts: 7,962
  • Life is like photography. Use negatives to develop
    • View Profile
    • Resell Rights Weekly
Re: Random Link
« Reply #1 on: March 30, 2011, 03:58:09 PM »
Hi John,

Here's what I use on WP:

Code: [Select]
<a href="http://MyDomain.com/Randomlink[php]echo rand(1, 10);[/php].php">Click here</a>


Which results in "http://MyDomain.com/Randomlink1.php" through "http://MyDomain.com/Randomlink10.php"

For "regular" site:

Code: [Select]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript"><!--
var links = new Array();
links[0]="http://www.site1.com";
links[1]="http://www.site2.com";
links[2]="http://www.site3.com";   
links[3]="http://www.site4.com";
links[4]="http://www.site5.com";

function getRandomLink() {
var randomNum = Math.floor(Math.random()*links.length);
window.location = links[randomNum];
}
//--></script>
</head>

<body>
<form name="" action="">
<input type="button" value="Click Here!" onclick="getRandomLink()" />
</form>
</body>
</html>

Hope that helps,
Mark
“Keep away from people who try to belittle your ambitions. Small people always do that,
but the really great makes you feel that you, too, can become great.”
~ Mark Twain

Offline SurfSmarter

  • Sr Member
  • Posts: 516
    • View Profile
Re: Random Link
« Reply #2 on: March 31, 2011, 12:38:13 PM »
Thanks Mark

Will try this on the weekend.

John