Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Google Adsense add-on for Vanilla 1
Hello,
I wanted to put some google ads on my forum. but the only extention available is only available for Vanilla 0.9.2, and i have vinilla 1
so how can can i put the ads on their without an add on.
I woul appreciate you help
thank you
0
This discussion has been closed.
Comments
1. Create a directory in your extensions directory. I created one called "Adsense"
2. Create a file called "default.php" inside the new directory.
3. Include the following code:
?php /* Extension Name: Google Adsense Extension Url: www.lussumo.com Description: Adds Google Adsense Version: 0.1 Author: Alexis Bellido Author Url: http://www.teleworkpeople.com */ if(in_array($Context->SelfUrl, array("index.php", "categories.php", "comments.php", "search.php", "post.php", "account.php" , "settings.php"))){ $adcode = <<< ENDCODE <div id="adsense-vertical"> <script type="text/javascript"><!-- google_ad_client = "pub-8679467187142369"; google_ad_width = 120; google_ad_height = 240; google_ad_format = "120x240_as"; google_ad_type = "text"; google_color_border = "B44551"; google_color_bg = "FFFFFF"; google_color_link = "B44551"; google_color_url = "B44551"; google_color_text = "B44551"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div> ENDCODE; $Panel->AddString($adcode,false); } ?>
4. Replace pub-XXXXXXXXX with your Adsense publisher code, you can replace the whole code of Google in fact. I'm just putting some generic one.
Of course the code can be improved and Adsense put in another locations but this is working for me and I hope it can give you an idea of what to do.
Actually it's the same code I used in 0.9.2.
Regards!
How would you place it elsewhere on a Vanilla forum? I've seen the add-on for placing it in the side panel, but not above the discussions or categories listing page. Have any ideas?
Thanks
if ($Context->Session->UserID == 0) { // Rest of addon code goes here. Code only runs if visitor is not signed in. }
$NoticeCollector->AddNotice($adcode);
instead of$Panel->AddString($adcode);
$Panel->Addstring
bit to$NoticeCollector->AddNotice
Otherwise, here is an example using a delegate:
<?php /* Extension Name: Adsense for Guests Extension Url: www.lussumo.com/Add-ons/ Description: Adds Google Adsense at the top of the discussions Version: 0.2 Author: WallPhone, based on existing code by Alexis Bellido Author Url: http://wallphone.com */ function InjectAdsense() { echo '<div align="center"> <script type="text/javascript"><!-- google_ad_client = "pub-5163550033929978"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_type = "text_image"; google_ad_channel ="3348340772"; google_color_border = "FFFFFF"; google_color_bg = "EEEEEE"; google_color_link = "008000"; google_color_text = "000000"; google_color_url = "336600"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script></div>'; } if ( ($Context->Session->UserID == 0) && (in_array($Context->SelfUrl, array("index.php", "categories.php", "comments.php", "search.php", "post.php", "account.php", "settings.php"))) ){ $NoticeCollector->AddNotice('Please <a href="'.GetUrl($Configuration, 'people.php'). '">sign in</a> or <a href="'. GetUrl($Configuration, 'people.php', '', '', '', '', 'PostBackAction=ApplyForm'). '">apply for membership</a> to remove the ads'); $Context->AddToDelegate('NoticeCollector', 'PostRender', 'InjectAdsense'); } ?>
EDIT: Fixed typos, tested code, centered ad-block, improved readability, and removed a bug.
Oh, and change your
google_ad_client = "pub-5163550033929978";
! That one is mine... but don't hurry, I appreciate the exposure!Mark: Found a bug with the notice running into the top of the search page in both IE and Firefox: