vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   vBulletin 3 Request - Random Quotes (https://vborg.vbsupport.ru/showthread.php?t=324856)

Alice 04-01-2017 06:30 PM

vBulletin 3 Request - Random Quotes
 
Hello Again,

Does anyone happen to know the best method to have random quotes displayed everytime a page in vBulletin is refreshed?

An image of where I have setup for the quotes to be displayed is as follows:

http://i.imgur.com/29KA8Fk.png?1

And the code for that is:

Code:

<table class="tcat" cellpadding="4" cellspacing="0" border="0" width="100%" align="center" style="border-top:1px solid $stylevar[tborder_bgcolor]; border-bottom:1px solid $stylevar[tborder_bgcolor]">

<tr>
    <td height="1" bgcolor="$stylevar[tcat_bgcolor]">
     
    </td>
<tr>
    <td align="center" bgcolor="$stylevar[select_bgcolor]">
<font face="verdana,arial,helvetica" size="1" ><i>"Quote Text."</i> - <b>Quote Author</font>
    </td>
<tr>
    <td height="1" bgcolor="$stylevar[tcat_bgcolor]">
     
    </td>

</table></table>
</div>

Hopefully, someone out there is able to provide some insight. Thank you,

MarkFL 04-01-2017 06:44 PM

What I would do is define a 2D array of quotes, where each element of the array contains a quote and the author, and then generate a random number between 1 and the length of the array (inclusive), then pass the selected array element to your template. :)

Alice 04-01-2017 06:48 PM

Quote:

Originally Posted by MarkFL (Post 2584601)
What I would do is define a 2D array of quotes, where each element of the array contains a quote and the author, and then generate a random number between 1 and the length of the array (inclusive), then pass the selected array element to your template. :)

How would I interface that with a vbulletin template though? Like there are plenty of random tutorials out there that involve php code, but I don't know how to integrate that into a vBulletin template so its a little confusing, you know?

MarkFL 04-01-2017 06:52 PM

You could use a global plugin hook, and I believe in vB 3 you don't even need to register the variables in your template.

I don't have time right now, but if you want, I will look into creating a vB 3.8.x product to do this. :)

Alice 04-01-2017 06:53 PM

So you can use the plugin in much the same way as I did to define the $quotemain for the footer template, right?

Code:

eval('$quotemain= "' . fetch_template('quotes_main') . '";');
eval('$quotetext= "' . fetch_template('quotes_text') . '";');

It might be a good idea. I know so many people still use 3.8.x, heck I still know someone who still uses 2.3.x LOL!

--------------- Added [DATE]1491083304[/DATE] at [TIME]1491083304[/TIME] ---------------

Quote:

Originally Posted by MarkFL (Post 2584603)
You could use a global plugin hook, and I believe in vB 3 you don't even need to register the variables in your template.

I don't have time right now, but if you want, I will look into creating a vB 3.8.x product to do this. :)

Okay, so I got somewhere with this. In the quotes_main template (which is called in the footer template as &quotemain), I added:

Code:

<script type="text/javascript" src="clientscript/quotes_database.js"></script>
<script type="text/javascript" src="clientscript/quotes_call.js"></script>

The contents of the quotes_database.js is:

PHP Code:

    <!-- Hide the script from old browsers
    
function getQuote() {
      
// Create the arrays
      
quotes = new Array(4);
      
sources = new Array(4);

      
// Initialize the arrays with quotes
      
quotes[0] = "When I was a boy of 14, my father was so ignorant..." +
      
"but when I got to be 21, I was astonished at how much he had learned " +
      
"in 7 years.";
      
sources[0] = "Mark Twain";
      
quotes[1] = "Everybody is ignorant. Only on different subjects.";
      
sources[1] = "Will Rogers";
      
quotes[2] = "They say such nice things about people at their funerals " +
      
"that it makes me sad that I'm going to miss mine by just a few days.";
      
sources[2] = "Garrison Keilor";
      
quotes[3] = "What's another word for thesaurus?";
      
sources[3] = "Steven Wright";

      
// Get a random index into the arrays
      
Math.floor(Math.random() * quotes.length);

      
// Write out the quote as HTML
      
document.write("<dl style='background-color:#F7D7C8'>\n");
      
document.write("<dt>" "\"<i>" quotes[i] + "</i>\"\n");
      
document.write("<b><dd>" "- " sources[i] + "</b>\"\n");
      
document.write("<dl>\n");
    }
    
// Stop hiding the script --> 

And the contents of quotes_call.js is:

PHP Code:

      <!-- Hide the script from old browsers
      getQuote
();
      
// Stop hiding the script --> 

And this is how it shows up on my forum:

http://i.imgur.com/WKaQou4.png?1

-Sara

blind-eddie 04-01-2017 08:02 PM

Use this.... edit to your liking
I have an edited version of it on my site.

https://vborg.vbsupport.ru/showthrea...highlight=tips

Alice 04-02-2017 12:44 AM

Quote:

Originally Posted by blind-eddie (Post 2584607)
Use this.... edit to your liking
I have an edited version of it on my site.

https://vborg.vbsupport.ru/showthrea...highlight=tips

Thank you so much for your contribution. I've actually already implemented what I included above and it works splendidly :)


All times are GMT. The time now is 12:04 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01069 seconds
  • Memory Usage 1,749KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (2)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete