How can I show a series of random images in a WordPress text widget using HTML/Javascript? -
i'm using wordpress 3.0.5 on dreamhost, trying create text widget in sidebar show random set of 9 (9) client logos. there total of 12 logos, located in /wp-content/clients folder, named logo1.jpg thru logo12.jpg.
the idea choose first image randomly, next 8 images in sequential order avoid duplicates.
update
got working, tips everyone!
here final, working version:
<div id="client-logos"></div> <script type="text/javascript"> totallogos = 12; firstpart = '<img src="/wp-content/clients/logo'; lastpart = '.jpg" height="50" width="110" />'; var r = math.ceil(math.random() * totallogos); var content = document.getelementbyid('client-logos').innerhtml; document.getelementbyid('client-logos').innerhtml = firstpart + r + lastpart; var t=0; (t=0;t<8;t++) { if (r == totallogos) { r=0; } r++; var content = document.getelementbyid('client-logos').innerhtml; document.getelementbyid('client-logos').innerhtml = content + firstpart + r + lastpart; } </script>
document.write() runs before page finishes loading.. should use else..
first of all, should object of div container id:
your html:
<div id="containerid"></div> <script> var elem = document.getelementbyid('containerid'); elem.innerhtml= "firstpart + r + lastpart"; </script>
Comments
Post a Comment