-
-
CommentAuthorJeremyD
- CommentTimeJan 21st 2007 edited by JeremyD on the 21st January 2007 at 15:30:37 EST
http://zilladesigns.net
see on the side where I have my latest template, Zilla Six? Well I'm going to be taking a break from dishing out templates for a while and i want that area to randomly display a different design picture along with its name, demo and download links.
How do I do this? thanks in advance. free Bakie to the giver of the answer.
-
-
-
CommentAuthorChristopher
- CommentTimeJan 21st 2007
Add this code somewhere in your PHP document:<?php
$templates = array(
'<img src="http://www.zilladesigns.net/images/designs/z4.jpg" border="0"><br />
Missing Piece(<a href="http://www.zilladesigns.net/designs/zillagfour/index.html">Demo</a> ¤ <a href="http://zilladesigns.net/site/download-manager.php?id=11">Download</a>)',
'S<img src="http://www.zilladesigns.net/images/designs/z5.jpg" border="0"><br />
Missing Piece(<a href="http://www.zilladesigns.net/designs/zillafive/index.html">Demo</a> ¤ <a href="http://zilladesigns.net/site/download-manager.php?id=11">Download</a>)',
'<img src="http://www.zilladesigns.net/images/designs/z6.jpg" border="0"><br />
Missing Piece(<a href="http://www.zilladesigns.net/designs/zillasix/index.html">Demo</a> ¤ <a href="http://zilladesigns.net/site/download-manager.php?id=11">Download</a>)',
);
$rand = rand(0, (count($templates)-1));
?>
Edit the array's and add more / less as needed, e.g. change the image paths and the download links etc.
Then where you want to show a random template use:<?php echo $templates[$rand]; ?>
Then that will pull 1 line of the array up above, which includes your image / download / preview contents, etc.
Simple hey
-
-
-
CommentAuthorJeremyD
- CommentTimeJan 21st 2007
even though i already said thanks on MSN---- Thanks :) -
-
- CommentAuthorainslie
- CommentTimeJan 21st 2007 edited by ainslie on the 21st January 2007 at 16:36:09 EST
Impressive
I think I may have a use for that too. -
- CommentAuthorricardo
- CommentTimeJan 22nd 2007
Hi everyone!
Does anyone know how to the random display but in normal html, ive searched but i only found javascripts but they dont allow to display one thing each time the page is loaded, the ones i found only let the user display 3 images and text at a time.
Thanks -
- CommentAuthoraanimo
- CommentTimeJan 22nd 2007
Can't do random display in pure HTML, ricardo, you'll need something like PHP -
-
CommentAuthorChristopher
- CommentTimeJan 22nd 2007 edited by Christopher on the 22nd January 2007 at 12:09:56 EST
In pure html it isn't possible (obviously). PHP is the simplest and easiest way, but you can do the same thing in JavaScript as well if you want. Put this code inside your head tags.<script type="text/javascript">
// Create The Array With The Content To Randomise
var Templates=new Array()
Templates[0] = 'This is the first random line of text.';
Templates[1] = 'Here is the second.';
Templates[2] = 'Finally a third, purely because I used 3 in my first PHP example';
// Do Not Edit Below This Line
var T = Templates.length;
var whichTemplates=Math.round(Math.random()*(T-1));
function showTemplates(){document.write(Templates[whichTemplates]);}
</script>
Then where you want to display your random stuff inside your website, call it using this code:<script type="text/javascript">showTemplates();</script>
The above code will validate as XHTML as well, although it won't degrade at all if the end-user has JavaScrit turned off, so I'd still say use PHP if you can. But if not, here's a solution for you to randomise some stuff. -
-
- CommentAuthorricardo
- CommentTimeJan 23rd 2007
Hi thanks for the help guys, the problem is that im on Blogger and it doesnt accept php
at the moment i have the following inside a html/javascript widget:
<center><script language="JavaScript">
//store the quotations in arrays
quotes = new Array(10)
quotes[0] = "<<<<quote>>>>";
quotes[1] = "<<<<quote>>>";
quotes[2] = "<<<<quote>>>";
quotes[3] = "<<<<quote>>>";
quotes[4] = "<<<<quote>>>";
quotes[5] = "<<<<quote>>>";
quotes[6] = "<<<<quote>>>";
quotes[7] = "<<<<quote>>>";
quotes[8] = "<<<<quote>>>";
quotes[9] = "<<<<quote>>>";
//calculate a random index
index = Math.floor(Math.random() * quotes.length);
//display the quotation
document.write("\n");
document.write(quotes[index]);
//done
</script></center>
How can i modify it to display a small pic and a link instead of the text that is displayed now?
Thanks -
-
CommentAuthorChristopher
- CommentTimeJan 23rd 2007
Untested but should work.<script type="text/javascript">
// Create The Array With The Content To Randomise
var Items=new Array()
Items[1] = '<img alt="Image Alt" src="http://website.com/image1.jpg" /> <a href="http://website.com/">Link Text 1</a>';
Items[2] = '<img alt="Image Alt" src="http://website.com/image2.jpg" /> <a href="http://website.com/">Link Text 2</a>';
Items[3] = '<img alt="Image Alt" src="http://website.com/image3.jpg" /> <a href="http://website.com/">Link Text 3</a>';
Items[4] = '<img alt="Image Alt" src="http://website.com/image4.jpg" /> <a href="http://website.com/">Link Text 4</a>';
Items[5] = '<img alt="Image Alt" src="http://website.com/image5.jpg" /> <a href="http://website.com/">Link Text 5</a>';
// Do Not Edit Below This Line
var I = Items.length;
var whichItems=Math.round(Math.random()*(I-1));
function showItems(){document.write(Items[whichItems]);}
showItems();
</script> -
-
- CommentAuthorricardo
- CommentTimeJan 23rd 2007 edited by ricardo on the 23rd January 2007 at 10:15:08 EST
Thanks, will test it later, i thought about using that code between '' but ive had problems before when inserting javascripts so i thought about asking it here.
Will let you know if it worked
1 to 10 of 10
