Blogger Beta: Random Quote Generator
I've had a request on getting a random quote generator to work in Blogger Beta directly under the heading. Well, Eastendist, this is your lucky day! Hans from Beautiful Beta had done a post on a sticky message board and I used that hack with minor tweaks to get the random quote generator to work in Blogger Beta.
Look at this post, Sticky Message Board, and follow the instructions. Remember after you get it up and running, you can change the appearance in the code that you put in "/* Variable definitions" and in the CSS section to fit the your blog. Make sure you place this:
<div id='content-wrapper'>directly below:
<div id='message-board'>
<b:section class='msgbrd' id='msgbrd' maxwidgets='1' showaddelement='yes'/>
</div>
<div id='header-wrapper'>because this is the part of the code that puts the quote generator below your header. When you have all the code in your template and saved it, open the Layout Editor and under the header will be a new element. Click 'Add a Page Element' , and select 'Configure HTML/JavaScript'. Click on 'Edit HTML' and add this to the window:
<i><center>You can change the quotes whenever the whim strikes you. You can even add more quotes...just follow the layout and increase the 'Array(6)' for each quote. Note that even though it says 'quote 5', the 'array' says 6. That is because it starts with 0.
<center><script language="JavaScript">
//store the quotations in arrays
quotes = new Array(6);
quotes[0] = "So many cats, so few recipes.";
quotes[1] = "Use the best: Linux for servers, Mac for graphics, Windows for Solitaire.";
quotes[2] = "That's not a haircut. That's a cry for help.";
quotes[3] = "The last thing I want to do is hurt you. But it's still on the list.";
quotes[4] = "Some days it's just not worth gnawing through the leather straps.";
quotes[5] = "Doing for blogging what Ghengis Khan did for social work.";
//calculate a random index
index = Math.floor(Math.random() * quotes.length);
//display the quotation
document.write("\n");
document.write(quotes[index]);
//done
</script>
</center></i>
Have fun putting in your favorite quotes!
Update 11/11/06: I've had some requests on how to put in more quotes, so here are more explicit instructions on doing just that. This is like the 'formula'. I know, Algebra is scary, but this is only a tiny formula with hardly any numbers and a couple of 'x's!
quotes = new Array(X + 1);
and you add another line for each new quote:
quotes[X] = "Your new quote";
Let's say you want 10 quotes. In 'Array you will put 11 (which is the x +1 or 10 + 1 from the formula). That will make your code look like this:
first part of code.....If that doesn't clear it up, let me know!
quotes = new Array(11);
quotes[0] = "So many cats, so few recipes.";
quotes[1] = "Use the best: Linux for servers, Mac for graphics, Windows for Solitaire.";
.....blah, more quotes, blah....
quotes[10] = "Doing for blogging what Ghengis Khan did for social work.";
.....last part of code
Update 11/13/06: See Blogger Beta: Random Quote Generator - Part 2
44 Comments:
wow, thanks for the response, annie!
i had a fairly good crack at it, and although it has appeared, I still feel something is a little fishy - I have copied Hans' code into my own template so I should be getting his design in order for me to adjust; however, nothing.
Ive looked at the code, and Hans' design settings are in there, so I can only assume I have made a mistake.
Any thoughts?
thanks once again!
@eastendist, I think I found the culprit. In the code I posted for the 'Page Element', I made an error which may effect the outcome. I put in an extra line of code:
</center></i>
Remove that from your 'Page Element' and things should work.
If not, email me and I will send you a copy of a basic Minima code with the changes in red so you can compare. But, I think removing that line will do it. At least, I hope so! Sorry about the mistake...it was late and I was seeing double, so apparently I posted in double too!
Oh, BTW, I corrected the code in the post to reflect the change.
nice hack! Thank you soooo much!
I am having a prob. I cant add any more quotes. I increased the array to 11 for 10 qoutes. But somethin is going wrong... pls help
This is SWEET!
I found you somehow, not sure, but originally through your beta 3 column test site. I've been wanting to get my blog into 3 column land. I am not a geek, but I try.
Would it be OK if I use your 3 column layout to mess with my site? I'll give props if I can get it to work. Thank you!!
Hey, thanks for coming up with this hack. I am using "harbor" as my template and I can't find the column to put the code into.
Care to help?
I decided to use this one differently! Because of recent cosmetic changes to my blog, I removed the message board.
Instead, I decided to use your random quote generator within the header, generating random description lines. Take a look at it here.
If you want something like that, search for the header section in your template. Look out for these lines:
<div class='descriptionwrapper'>
<p class='description'><data:description/></p>
</div>
Replace <data:description/> with Annie's javascript.
That should do it.
Cheers!
@Thomas, here is what you need to do. Find:
<div id='main-wrapper'&glt;</div&glt;
add:
<div id='content-wrapper'&glt;
<div id='message-board'&glt;
<b:section class='msgbrd' id='msgbrd' maxwidgets='1' showaddelement='yes'/&glt;
</div&glt;
Then follow the rest of the instructions in this post for entering the code to the page element.
@Alastor, I like that...great idea!
@andie d., feel free to use the template and hack away! Props are always sweet!
@cyber-buff, the part of the code that changes:
quotes = new Array(X + 1);
and you add another line for each new quote:
quotes[X] = "Your new quote";
So...if you have 10 quotes it will look like this:
first part of code.....
quotes = new Array(11);
quotes[0] = "So many cats, so few recipes.";
quotes[1] = "Use the best: Linux for servers, Mac for graphics, Windows for Solitaire.";
.....blah, blah....
quotes[10] = "Doing for blogging what Ghengis Khan did for social work.";
.....last part of code
Good one, Annie! Based on this idea, I am thinking about a Random text display widget that can be added to a blog without editing HTML.
@Ramani, what a nice compliment from the beta hacker king! Thanks!!
I'm anxious to see what you come up with.
Thanks Annie. Great job.Btw, is there a limit to the number of quotes that can be used?
@milind, read my response to cyber-buff and that will tell you how to add more quotes!
@thomas, I just noticed that when answering your comment, it screwed up. Anyway, where it says &glt; , put >
Sorry if it caused any problems:-(
It's lovely, come take a look.
I did learn that one has to avoid quotes within the quote -- hard when one is quoting CS Lewis. Also, one cannot use bold or italics.
Thanks so much.
Suzanne
Thanks for this hack, the first 5 quotes work just fine, but after i add more post (72 of them) it's wont function well. where did i do wrong. Please help. Thankz Annie
Thank you for this! It only took me 10 minutes to add it. You don't happen to have HTML code for a ticker for quotes. If not, this does the job.
Thanks again! Happy Blogging!
I've had so much trouble with this--i want to put it in the left sidebar, not the header, as a quote box. I've tried, but can't get the code right in the template...so the widget won't work. I wanted a quote box that allowed me to have unlimited or at least a good deal more than a month's worth of quotations-- preferably that changed quotes on refresh page (but i can do without that if it can only be done as a new quote per day). I have tried about 10 different scripts for this, including yours and am having a heck of a time getting any of them to work, though i checked and double checked and triple checked them all. I have one quotes widget (on the right sidebar) that works on my page, but it is limited to 31 quotes. I'd like to change that one too.
So primarily, I'm asking if you can tell me how to place this code if i want it in sidebar?
Also- it's unclear about what i should look for, other than the usual stuff mentioned in these kinds of instructions, that might keep the code from working. If you need more details let me know--sorry this was so long...
thanks for any help!
Jae Baeli
http://usedbythemuse.blogspot.com
@Jan, interesting question. I don't have the time to devote to looking into it properly right now, but when I do, I will respond whether or not I found the answer.
good job on the code!
did'nt work for me initially before I realized you can't have (") in the quotes. cheers!
I have been trying to configure this with the newer (not beta, not old) version of blogger. I add in the code above under div id='header_wrap', but when I save, it says that I am not closing div's properly. any advice on how/where I need to close the divs?
Thanks
@NewzWorth, You will have to send me the template file so I can take a look at it.
thanks a lot...
THANK YOU SOOOOO MUCH!
You are awesome! :)
Been searching for this for ages!!!! THANK YOUUUUUUU!!!
http://powderpink-snowflake.blogspot.com/
I agreed with you,In my point of view it is a very good blogging way with the the use of different HTML.it is very appreciated that you give more then on quote on your site.
hey this is wonderful... thanks a lot mate!!
Quite old post, but something I was searching for. Thanks!
awesome! thanks!
though, you need to change a few things in explaining, I had to figure it out myself.
but it's still AWESOME.
thanksss!!
http://pcdcftw.blogspot.com
It only took me ten minutes to add this thank you!
I have this random quote thingy on my blog for some time and it works mint, however, I was trying to add it to my side bar as well but I wont work. Suggestions anyone?
hi, this helped a lot :) cheers! :))
Hey! thanks for this post. I like it a lot.
Thanks, I like this.
If you post a blog on Myspace does it automatically upgrade you to the BETA profile?
I just want to say thank you, i have been looking for this for a day and a half and was about to give up hope. Other websites that had any type of info were all jiberish to me but this was very easy for someone new to blogging. Again, thank you!
thanks for the helpful tips. I was wondering if you happen to know how to generate the quotes if they are in a separate file.
I was wondering if I could put the quotes separated by a paragraph space like this:
First quote
Second quote
etc.
Do you know if something like that is possible?
I'm trying to use it as a recipe randomizer and it worked wit 6 but not with 21 can you help?
wow, thanks for the response, annie!
i had a fairly good crack at it, and although it has appeared, I still feel something is a little fishy - I have copied Hans' code into my own template so I should be getting his design in order for me to adjust; however, nothing.
Ive looked at the code, and Hans' design settings are in there, so I can only assume I have made a mistake.
Any thoughts?
thanks once again!
What a grean Script . Im gonna use it in my blog.
BTW Thanks .