Wednesday, August 15, 2007, 01:57 AM
Posted by Administrator
Posted by Administrator
As you can see, AdSense is now available on my blog. See the ads on the upper-left corner of the site?Signing up for AdSense is easy. Just head on over to www.google.com/adsense and register as a new user. Once you are approved, which may take up to 48 hours (much sooner in my case), you can begin adding AdSense code to your site.
To show the AdSense code in my site, I had to change three files included as part of the Simple PHP Blog installation. One of them,
themes/modern/themes.php, was relatively simple to change. After the line:
echo( "\n<!-- SIDEBAR MENU BEGIN -->\n" );I added the following:
//ADSENSE
theme_menu_block( menu_display_adsense(), "ADSENSE" );This added the AdSense block to the very top of the sidebar. If you wanted to make it appear lower in the sidebar, simply move the above two lines of code wherever you want it to be placed.
The bulk of the changes occurred in the
scripts/sb_themes.php file. I created a new function:function menu_display_adsense() {
// Title: Adsense mod for sPhpBlog
// Author: Bill
// Returns adsense picture/script
global $lang_string, $user_colors;
$str = '<script type="text/javascript"><!--' . "\n";
// *** Make sure you use your own pub number here! ***
$str .= 'google_ad_client = "pub-xxxxxxxxxxxxxxxx";' . "\n";
// *** Make sure you use your own pub number here! ***
$str .= 'google_ad_width = 160;' . "\n";
$str .= 'google_ad_height = 600;' . "\n";
$str .= 'google_ad_format = "160x600_as";' . "\n";
$str .= 'google_ad_type = "text_image";' . "\n";
$str .= 'google_ad_channel = "";' . "\n";
$str .= 'google_color_border = "' . $user_colors[ 'menu_title_bg' ] . "\";\n";
$str .= 'google_color_bg = "' . $user_colors[ 'menu_bg' ] . "\";\n";
$str .= 'google_color_link = "' . $user_colors[ 'link_reg_color' ] . "\";\n";
$str .= 'google_color_text = "' . $user_colors[ 'menu_text' ] . "\";\n";
$str .= 'google_color_url = "' . $user_colors[ 'menu_title_text' ] . "\";\n";
$str .= '//-->' . "\n";
$str .= '</script>' . "\n";
$str .= '<script type="text/javascript"' . "\n";
$str .= ' src="http://pagead2.googlesyndication.com/pagead/show_ads.js">' . "\n";
$str .= '</script>' . "\n";
$result = array();
$result[ 'title' ] = $lang_string[ 'menu_adsense' ];
$result[ 'content' ] = $str;
return ( $result );
}The nice thing about this function is the integration of the theme colors. This way, if you change the colors of your theme in the future, the AdSense colors will change to match your theme. Note: to find your pub number, use the AdSense site to generate some example code. You should see the pub number in the generated code.
Finally the last file I changed was
languages/english/strings.php. I added a new line:$lang_string['menu_adsense'] = "";amongst the other $lang_string definitions found in the file. Note that there is nothing between the quotes. You could add a title to the AdSense block by adding one between the quotes, but I think it looks better with no text.
That's it! The modern theme should now automatically display AdSense ads when viewed. You should be able to change other themes using a similar process.
Bill




( 3.1 / 26 )

Archives


