Random Quote - please help me implement such function
I'd love to use random inspirational quotes in the header of my Wordpress blog. However, I need some assistance with the technical side.
Could you please share with me or direct me to the script that will work? Please give me directions as to how to input such script to the html file to make it work. It'll replace the foreign words in the header of my blog.
I'm deeply grateful for every bit of help :)
Start by declaring an array; each quote will be one element in the array. So you have:
var quotes = new Array(11);
quote = "You are what you eat";
quote = "Government is a lousy master and a treacherous servant";
quote = "For the first time in history, it is possible to meet the needs for 100% of the global population";
So if you have 11 quotes your last one will be quote;
Then, to choose a random number of the array make a random number generator:
var choice = Math.floor(Math.random()*11);
Math.floor is to get an integer number. ^That 11 is because I assume 11 quotes; adjust it to your number. (Math.random() gives you a random decimal between 0 and 1)
Then just write it.
Write that in text editor and save as something like quote_gen.js
Then upload the file onto your sever. Where you want it to appear, insert the script:
Thanks a lot runningbird.
I followed your directions and unfortunately it didn't work. Luckily, I managed to find a script that worked out for me. I did nothing but paste this in the place it appeared:
I opt for one more tweak. Perhaps you could help me out. Therre are two paragraphs in the place for my quotes. The difference between them is style (class="para1" and class="para2"):
<p class="para1">Quisque sed felis. </p>
<p class="para2">Quisque sed felis. </p>
I pasted my script inside the <p class="para1"> </p> and it worked out well. I would like to place the quote author in <p class="para2"> </p>. I can't do that by placing the same script because the author would be chosen randomly, instead of according to the chosen quote. So there are two ways in which you could help me out:
1. Verify the script code and make it write two paragraphs with style defined instead of just plain text
Thanks a lot and looking forward to hearing from you again:)
UPDATE: Help! This script works only for 3 quotes. When I add fourth one, nothing shows up. Where can I change the max. number of quotes? Please help
|All times are GMT. The time now is 04:59 AM.|
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2010 by Pavlina LLC