| | |||||||
| Technology & Technical Skills Computer skills, hardware, software, internet topics, gadgets, programming |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Senior Member Join Date: Oct 2007
Posts: 341
|
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 Ralph |
| | |
| | #2 (permalink) |
| Senior Member Join Date: Oct 2008 Location: Cleveland, OH
Posts: 614
|
I can tell you how to do it in javascript - very easy. Start by declaring an array; each quote will be one element in the array. So you have: var quotes = new Array(11); quote[0] = "You are what you eat"; quote[1] = "Government is a lousy master and a treacherous servant"; quote[2] = "For the first time in history, it is possible to meet the needs for 100% of the global population"; etc. So if you have 11 quotes your last one will be quote[10]; 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. document.write(quotes[choice]); 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: <script src="quote_gen.js" type="text/javascript"></script> |
| | |
| | #3 (permalink) |
| Senior Member Join Date: Oct 2007
Posts: 341
|
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: Code: <script type="text/javascript">
// <![CDATA[
Array.prototype.random = function(limit)
{
if (typeof limit == 'undefined' || limit < 0) limit = 1;
else if (!limit) limit = this.length;
for (var i = 0, source = this, target = new Array(), n = source.length; i < limit && n > 0; i++)
{
do { var index = Math.random(); } while (index == 1);
index = Math.floor(index * n);
target.push(source[index]);
source[index] = source[--n];
}
return target;
}
document.write(new Array(
// Enter the elements here:
'Tekst 1',
'Tekst 2',
'Tekst 3'
).random().join(''));
// ]]>
</script> 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 2. Create a javascript that uses the same variable as the first one in choosing between the texts. This way, if the quote 2 would be chosen in the first script, the second script would automatically choose author 2. I could make the list of authors corresponding to the list of quotes. 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 Ralph Last edited by Ralph; 03-23-2009 at 09:04 PM. |
| | |
| | #4 (permalink) |
| Senior Member Join Date: Oct 2008 Location: Cleveland, OH
Posts: 614
|
Unfortunately, I cannot really make sense of that script. Sorry mine didn't work out. I am not that adept in javascript, but I had made a random sentence generator when I was trying to learn it. Hopefully someone else can help you out.
|
| | |
| Bookmarks |
« Previous Thread
|
Next Thread »
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Random quote | Parthon | Social & Relationships | 7 | 01-13-2009 07:14 AM |
| What if everyone was living their purpose? Could the world still function? | cpalmer | Character & Contribution | 28 | 01-01-2009 01:41 AM |
| Who effectively managed to implement GTD? | Dolazy | Personal Effectiveness | 18 | 08-26-2007 01:40 AM |
| [Random] Yohojo's Sleeping Schedule [Random] | Yohojo | Health & Fitness | 1 | 02-06-2007 04:46 AM |
| Function pointers instead of dlls in C++ | Minsc | Technology & Technical Skills | 1 | 11-07-2006 08:01 AM |
All times are GMT. The time now is 03:07 AM.




