PDA

View Full Version : Help with a header plugin...


DivinoZarathos
07-15-2012, 04:33 PM
Hi all! I'm trying to create a random quote plugin for my board's header.
So far, i created the following plugin on global_bootstrap_init_start:

if ($result = $vbulletin->db->query_first
("
SELECT text, author
FROM " . TABLE_PREFIX . "cs_randomquotes
WHERE approved = 1
ORDER BY RAND() LIMIT 1
")
)
{
$templater = vB_Template::create('header_randomquote');
$templater->register('author', $result['author']);
$templater->register('text', $result['text']);

$randomquote = $templater->render();
}
else
$randomquote = '';

vB_Template::preRegister('header', array('randomquote' => $randomquote));

Then I created the header_randomquote template:

<div class="text">{vb:raw text}</div>
<vb:if condition="$author">
<div class="author">{vb:raw author}</div>
</vb:if>

And I finally edited my header template adding:

<div id="header_randomquote">{vb:raw randomquote}</div>

Query is ok (well, I think it's ok to get random entries)... but nothing is being shown. Can you find any error in my code? :S

Lynne
07-15-2012, 05:03 PM
Change your else to actually spit something out in $randomquote so you can see which path it is taking (if or else).

soniceffect
07-15-2012, 09:11 PM
Hi all! I'm trying to create a random quote plugin for my board's header.
So far, i created the following plugin on global_bootstrap_init_start:

if ($result = $vbulletin->db->query_first
("
SELECT text, author
FROM " . TABLE_PREFIX . "cs_randomquotes
WHERE approved = 1
ORDER BY RAND() LIMIT 1
")
)
{
$templater = vB_Template::create('header_randomquote');
$templater->register('author', $result['author']);
$templater->register('text', $result['text']);

$randomquote = $templater->render();
}
else
$randomquote = '';

vB_Template::preRegister('header', array('randomquote' => $randomquote));

Then I created the header_randomquote template:

<div class="text">{vb:raw text}</div>
<vb:if condition="$author">
<div class="author">{vb:raw author}</div>
</vb:if>

And I finally edited my header template adding:

<div id="header_randomquote">{vb:raw randomquote}</div>

Query is ok (well, I think it's ok to get random entries)... but nothing is being shown. Can you find any error in my code? :S


Your missing a closing brace on your IF/ELSE block in your plugin