PDA

View Full Version : random banner code - what am I doing wrong?


Lpspider
07-12-2012, 11:03 PM
I found some code on another forum that's supposed to show a random banner within vbulletin. People posting in the thread got it to work, but I'm stuggling. If someone wouldn't mind taking a look and telling me what I'm doing wrong, I'd greatly appreciate it.

I created a new plugin, with the hook location of "global_start" with this code:

$banner[1] = "<center><a href=\"http://advertiser-edit.com/?utm_source=website.org&utm_medium=banner&utm_campaign=websiteleaderboard\"><img src=\"http://www.website.org/leaderboard_books_design.jpg\"></a></center>";
$banner[2] = "<center>
<script type=\"text/javascript\"><!--
google_ad_client = \"ca-pub-numbersremoved\";
google_ad_slot = \"4591232780\";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type=\"text/javascript\"
src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
</script></center>";

$rotator = rand(1, 2);

$bannerrotator = $banner[$rotator];

I've tried placing $bannerrotator in the bottom of the navbar template and also in the ad location in the ads section, but neither work. Instead I get "$bannerrotator" where the ad should appear. What am I doing wrong?

Thanks guys.

kh99
07-12-2012, 11:50 PM
The problem is that that was intended for vb3. But it should work in vb4 with a few changes. First, use hook parse_templates. Next, add the following line to the end of the plugin code (for the navbar template):
vB_Template::preRegister('navbar', array('bannerrotator' => $bannerrotator));


Then in the navbar template, use {vb:raw bannerrotator}.

Lpspider
07-13-2012, 12:22 AM
Thank you very much for the help. Got it working. :D

GOJOHNNYGO
10-12-2012, 01:10 PM
I am having the same trouble. Total noob question...

When you say the navbar template, where do I find this to insert the {vb:raw bannerrotator}. ?

Lynne
10-12-2012, 02:58 PM
I am having the same trouble. Total noob question...

When you say the navbar template, where do I find this to insert the {vb:raw bannerrotator}. ?
Admincp > Styles & Templates > Style Manager > find style > Edit Templates

GOJOHNNYGO
10-12-2012, 03:49 PM
Thanks!

GOJOHNNYGO
01-02-2013, 09:49 PM
Okay, I have yet to get this to work properly. I posted this code:

$banner[1] = "<a href="http://bham-jk.com/showthread.php?1015-Meet-N-Mod-Party" target="_blank"><img src="http://i93.photobucket.com/albums/l72/JOHNNYP4409/MeetNModparty_zps9e808cc0.jpg" border="0" alt="MeetnModParty"/></a>";
$banner[2] = "<a href="http://www.tntaccessoriesnservicecenter.com/" target="_blank"><img src="http://i93.photobucket.com/albums/l72/JOHNNYP4409/TNTBannerBlack.png" border="0" alt="TNTaccessories"></a>>";

$rotator = rand(1, 2);

$bannerrotator = $banner[$rotator];

vB_Template:: preRegister('navbar', array('bannerrotator' => $bannerrotator));

Then put this in the "ad_global_below_navbar" template:

{vb:raw bannerrotator}

Then I get this error:
Parse error: syntax error, unexpected T_STRING in /home/bhamjk/public_html/includes/class_bootstrap.php(430) : eval()'d code on line 1

So, what have I done wrong?

kh99
01-02-2013, 10:00 PM
The problem is that you've put double quotes around strings that contained double quotes, so they're mismatched. If you use single quotes instead it should work, like:

$banner[1] = '<a href="http://bham-jk.com/showthread.php?1015-Meet-N-Mod-Party" target="_blank"><img src="http://i93.photobucket.com/albums/l72/JOHNNYP4409/MeetNModparty_zps9e808cc0.jpg" border="0" alt="MeetnModParty"/></a>';
$banner[2] = '<a href="http://www.tntaccessoriesnservicecenter.com/" target="_blank"><img src="http://i93.photobucket.com/albums/l72/JOHNNYP4409/TNTBannerBlack.png" border="0" alt="TNTaccessories"></a>>';

$rotator = rand(1, 2);

$bannerrotator = $banner[$rotator];

vB_Template:: preRegister('navbar', array('bannerrotator' => $bannerrotator));


Also I noticed that the $banner[2] string has >> at the end, I don't know if that's a typo or not.

ForceHSS
01-02-2013, 10:00 PM
dam just posted about the double >> but was beat to it

GOJOHNNYGO
01-02-2013, 11:28 PM
Thanks guys. I got those fixed. Not showing any errors now, but the banner still doesn't show up.

Using VB4 if that helps

kh99
01-02-2013, 11:36 PM
In the code you posted above, there's a space in "vB_Template:: preRegister" - I'm not sure if that's allowed.

Edit: oh...in the preRegister() call, you need to use 'ad_global_below_navbar' in place of 'navbar'.

GOJOHNNYGO
01-02-2013, 11:48 PM
Yeah, I added the space here to avoid the :p smilie

That did it!!!!! Awesome! Thanks guys!