« HOWTO take apart and repair an old NESPlanet Lugs »

Incorporating AdSense to b2evolution

Technical, PHP, 535 words   English (AU)

François has written an Adsense plugin for b2evolution for conveniently inserting Google Ads via the insertion of an Adsense tag.

This approach allows one to manually and simply drop [ adsense: ] tags throughout the post which will be automatically rendered as Google Ads.

Here is a method I found to add them on a more global level rather than manually adding in the post. You can also configure them based on each skin’s color scheme and dimensions.

Follow up:

First add a file that generates the Adsense code which I place in the skins folder with the rest of the base skin code.

insertAdsense.php

PHP:

<?php
global $gAdWidth$gAdHeight$gAdFormat$gAdBorder$gAdBgColor$gAdLinkColor$gAdTextColor$gAdUrlColor;
 
if (isset($gAdWidth) && isset($gAdBgColor))
{
echo '<center>
<script type="text/javascript"><!--
google_ad_client = "pub-5883679897688490";
google_ad_width = '.$gAdWidth.';
google_ad_height = '.$gAdHeight.';
google_ad_format = "'.$gAdFormat.'";
google_ad_type = "text";
google_color_border = "'.$gAdBorder.'";
google_color_bg = "'.$gAdBgColor.'";
google_color_link = "'.$gAdLinkColor.'";
google_color_text = "'.$gAdTextColor.'";
google_color_url ="'.$gAdUrlColor.'";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center>';
}
?>

Note: You can customise the above adsense code further, I believe there are a couple of other javascript parameters that you can add on the above code to further customise the Google ad.

Next you need to define those adsense settings at the skin level.

I add the following in the index.main.php file of the skin just after the
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directl$

Of course, put in the necessary values that fit your skin.

PHP:

if( !defined('EVO_MAIN_INIT') ) die'Please, do not access this page directl$
 
$gAdWidth=468;  // Width of the Ad
$gAdHeight= 60;  // Height of the Ad
$gAdFormat = "468x60_as";  // Format of the Ad
$gAdBorder = "ffffff";  // Color of the Ad's border
$gAdBgColor "ffffff";  // Color of the Ad's background
$gAdLinkColor "000000";  // Color of the links in the Ad
$gAdTextColor"222222";  // Color of the text in the Ad
$gAdUrlColor "0000ff";  // Color of the Url in the Ad

Including the code

You will need to look though the code and include the insertAdsense.php code where required.

PHP:

include("insertAdsense.php");

For me, I added the above line in the following files

  • _item_comment_form.inc.php - this renders the code for the comment form.
  • _item_content.inc.php - this renders the code for the post content which is called multiple times on the blog’s front page.
  • _item_feedback.inc.php - this renders the code for the feedback/coments etc. Include towards the top of this file so that it always appears just before the trackbacks and comments section.
  • _msgform.disp.php - this renders the code for the contact us message form.

Most skins use the default base form files in the skins folder. However for skins with their own custom forms, you should find the respective files in the skins folder. After which simply insert the following variation of the above.

PHP:

include(dirname(__FILE__)."/../insertAdsense.php");

Trackback address for this post

This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)

3 comments

  1. Permanent link for this comment Pradip Biswas Email said on
    This is very useful information. Thanks.
  2. Permanent link for this comment Keven Email said on
    What I really need to know is how to configure the adsense plugin so it knows what account to credit the ads to. My adsense login is different than any of my information on my b2evo blog, so I hope it's not based on that! At any rate, I tried the [adsense:] thing, and I didn't get any ads in the post- just [adsense:]
    Thanks in advance for any pointers!
    Keven
    www.dfwsupergeek.com
  3. Permanent link for this comment Brinley Ang® Email said on
    @Keven This post is 2 years old so the [adsense:] plugin may not be available with current b2evo. I'm not sure as I dont use it. However my solution which requires a fair bit of PHP coding know how still works as I am currently still using it with my b2evo blog.

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)
March 2010
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

Brinley Ang

Brinley Ang is a sysadmin, web dev, coder, geek boy, jedi knight fragger, caffine addict, deaf meloncholic and rockstar wannabe. Listens to the sex pistols and a wide assortment of heavy metal.

Make payments with PayPal - it's fast, free and secure!

Search
XML Feeds
home | portfolio | blog | contact
© 2010 - Brinley Ang
Valid xhtml