Tuesday, September 11, 2007, 03:22 PM
Posted by Administrator
Posted by Administrator
Here is a neat little code tweak that will integrate AdSense into the posts you make with Simple PHP Blog for the Modern theme. In the themes/modern/themes.php file, look for the following:// Display BODY TEXT
$blog_content .= $entry_array[ 'entry' ];
$entry_array[ 'entry' ] contains your blog entry, so all we have to do is to put the AdSense code into this variable in order to have it display automatically. The catch is that Google only allows you to display a maximum of 3 ad boxes on a page at a time, so there needs to be a way to determine how many have been displayed. This can be determined by looking at the $entry_array[ 'count' ] variable, which contains a numeric value of the current entry we are processing (0 = first entry, 1 equals second entry, etc). With that in mind, changing the above code to:
// Display BODY TEXT
if( ( $entry_array[ 'count' ] == 0 or $entry_array[ 'count' ] == 1 ) and $mode == 'entry' ) {
$blog_content .= '<center><script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxxxx";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text";
google_ad_channel = "";
google_color_border = "ffffff";
google_color_bg = "ffffff";
google_color_link = "5977b3";
google_color_text = "4d4d4d";
google_color_url = "5977b3";
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center>';
}
$blog_content .= $entry_array[ 'entry' ];
Ads will now automatically displayed on the first two posts displayed on a page. The key to this is the line:
if( ( $entry_array[ 'count' ] == 0 or $entry_array[ 'count' ] == 1 ) and $mode == 'entry' )
This checks to make sure we are only adding the AdSense code to the first two entries, as well as making sure it IS an entry (and not a comment).




( 3 / 100 )

Archives


