Automatically Integrating AdSense Into Simple PHP Blog Entries 
Tuesday, September 11, 2007, 03:22 PM
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).
one of us is wrong 
Friday, October 24, 2008, 02:27 PM / http://www.oneofusiswrong.com
We use the simplePHP blog software at our blog, www.oneofusiswrong.com, although we are not sure yet whether we will add this edit to the site. We did use the code you posted to put adsense ads along the side of the page.
playgamesonline 
Friday, September 5, 2008, 02:06 PM / http://www.playdigger.com
free action game play. fire fighter online. fre online fighting games free action game play. fire fighter online. fre
Americapublicsc 
Friday, September 5, 2008, 02:01 PM / http://public.findyourschool.info/
public schools in America. public schools in kansas. America public schools dat public schools in US public schools in America. public schools in kansas. America public schools dat
kevino 
Thursday, December 13, 2007, 06:05 AM / www.kevino-ng.com/blog
It is so good that you guys know about PHP. As a newbie like me, I just know how to read do not know how to apply.....
Administrator (Bill) 
Friday, December 7, 2007, 06:22 PM / http://manningtondeal.110mb.com
I've checked out your site, and it doesn't appear to be using SimplePHPBlog. This code won't work unless you are using SimplePHPBlog.

If I'm looking at the wrong site, just send me a link to the correct site and I'll be glad to check it out.

Thanks!
MK 
Thursday, December 6, 2007, 05:05 PM / www.boraskungfu.com
I enter the code EXACTLY as above and all I get when I refresh my blog in IE och Firefox is a blank webbrowser... why is that? I've added the code in Frontpage..

plz help
onlinetips 
Sunday, November 18, 2007, 04:40 AM / http://onlinetips.info
Hi. See your post at :
http://onlinetips.info/story.php?title= ... og_Entries
rter 
Sunday, September 16, 2007, 07:59 AM / http://www.therichspot.com
Great blog!
Administrator (Bill) 
Thursday, September 13, 2007, 10:39 PM
keeyit,
I haven't used WordPress myself, but check out Wordpress Plugins.
keeyit 
Thursday, September 13, 2007, 10:59 AM / http://www.keeyit.com
Do you know how to integrate the google adsense in wordpress using widgets text ?
Blogging The Movie 
Wednesday, September 12, 2007, 05:36 PM / www.bloggingthemovie.com
thanks I might need that php info for later use.
Administrator (Bill) 
Wednesday, September 12, 2007, 05:09 PM / http://manningtondeal.110mb.com
Remember, this is for Simple PHP Blog ONLY, and it will not work for other blogging software, such as WordPress.

Comments 

Add Comment

Fill out the form below to add your own comments.









Insert Special: