« HOWTO take apart and repair an old NESPlanet Lugs »

Incorporating AdSense to b2evolution

Technical, PHP, 535 words   Bookmark and Share

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.

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
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.


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.


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.


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

May 2024
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 software engineer, sysadmin, 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
home | portfolio | blog | links | contact
© 2024 - Brinley Ang
Valid xhtml