Now, grab your AdSense code snippet from Google...
<script type="text/javascript"><!--
google_ad_client = "pub-0123456789";
google_ad_width = 120;
google_ad_height = 600;
google_ad_format = "120x600_as";
google_ad_type = "text_image";
google_ad_channel = "1";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "006699";
google_color_text = "006699";
google_color_url = "006699";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
And paste it into the other open document...making some changes...
<?php echo "
<script type=\"text/javascript\"><!--
google_ad_client = \"$ad_pub_num\";
google_ad_width = 120;
google_ad_height = 600;
google_ad_format = \"120x600_as\";
google_ad_type = \"text_image\";
google_ad_channel = \"1\";
google_color_border = \"FFFFFF\";
google_color_bg = \"FFFFFF\";
google_color_link = \"$eb_linkcolor\";
google_color_text = \"$eb_linkcolor\";
google_color_url = \"$eb_linkcolor\";
//--></script>
<script type=\"text/javascript\"
src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
</script>
?>
...and save this file as ads.php.
Do you recognize the changes we made? We’ve told PHP to echo the code to the screen, and put in the variables that we set in the settings.php file.
Since we are doing an ECHO, we’re displaying the quotation marks in the output with the \” code (That’s the way the AdSense snippet works).
Now we are ready to call these files from the main web pages!
At the beginning of your content pages, you will want to add this code:
<?phprequire “settings.php”;?>
This tells the page that it requires the contents of Settings.php file to be included.
Including this code on each page sets the variables we will use throughout the site.
Now, call the ads in the places you want them:
<?phpinclude “ads.php”;?>
This will pull in the code from the ads page we made, including the variables we set, and show those ads wherever you care to place them.
So, your ad link colors will appear in a dark blue and the example publisher number - pub-0123456789 - will show up in the ads.
Name each one of your content pages as .php instead of .html, and you’ll be good to go!
If you decide you want to change colors of the ads (or change the AdSense publisher ID code), you only have to make that change in ONE file instead of 200 - the settings.php file!
2 Comments
Marcus
5/20/2009 10:50:45 am
Hello,
Reply
Leave a Reply. |
David Rentson
If this free PHP and MYSQL Tutorial is helpful for you... Great! Archives
October 2008
Categories
All
|