Adding Adsense to an Artisteer 2.5 generated Theme

adsense artisteer codeAs stated previously about adding a „share this“ button to your artisteer geenerated post, it became more difficult to do that due to the modular way artisteer works now.

Generally I had the idea, to show an add ad the front of a post/page/list and if there were comments another small link ad before the comment form or after the third post.

Widget Areas

The first 2 things are easy to do. Artisteer provides a top and bottom widget to place inside the content side of the page. You should make sure that the content width is wide enough to fit an ad into it, then you can simply use the execphp widget plugin and put the AdSense for Content™ program code into it.

It looks like this:

Top Widged Area

I took the AdSense for Content™ program code and used a html2php website to get the php equivalent of the html code and insert it in the Top Area Widget. You can use the Artisteer content wrapper to have it blend in better with your site.

<?php
echo "<div class="art-post">n";
echo "<div class="art-post-body">n";
echo "<script type="text/javascript"><!--n";
echo "google_ad_client = "pub-8428018818545773";n";
echo "/* ITRM-Top-728x90, created 9/7/10 */n";
echo "google_ad_slot = "9769476956";n";
echo "google_ad_width = 728;n";
echo "google_ad_height = 90;n";
echo "//-->n";
echo "</script>n";
echo "<script type="text/javascript"n";
echo "src="https://pagead2.googlesyndication.com/pagead/show_ads.js">n";
echo "</script>n";
echo "</div>n";
echo "<div class="cleared"></div>n";
echo "</div>n";
?>

This trick works for the bottom and the top widget area. Its big advantage is that you can easily change themes and you do not need to change a thing, it will jsut keep working. The orange marked text is the Artisteer generated code, while AdSense for Content™ program code is in green.

Inpost AdSense for Content™ program

For the inpost advertisement you need to hack some of the php-files though. Lets look at the easy ones first. We modify the index.php.

<?php
get_header();
$myadsensecount = 1; 
 if (have_posts())
 {
 while (have_posts())  
 {
 art_post();
 if ($myadsensecount == 3) {
 echo "<div class="art-post">n";
 echo "<div class="art-post-body">n";
 echo "<script type="text/javascript"><!--n";
 echo "google_ad_client = "pub-8428018818545773";n";
 echo "/* ITRM-Middle-728x15, created 9/7/10 */n";
 echo "google_ad_slot = "0720805316";n";
 echo "google_ad_width = 728;n";
 echo "google_ad_height = 15;n";
 echo "//-->n";
 echo "</script>n";
 echo "<script type="text/javascript"n";
 echo "src="https://pagead2.googlesyndication.com/pagead/show_ads.js">n";
 echo "</script>n";
 echo "</div>n";
 echo "<div class="cleared"></div>n";
 echo "</div>n";
 }
 $myadsensecount++; 
 }
 art_page_navi();
 } else {    
 art_not_found_msg();      
 }

get_footer();

What this does is to set the variable $myadsensecount to 1, and each time the loop is being process it adds 1 to it. After the third post the AdSense for Content™ program code will be inserted.

Now you can repeat that for other „list“ views aswell, for example the archive.php.

For single pages, like posts I only wanted to display a third ad above the comment form in case there were actually comments. Else there’d be 2 ads right above each other. This is my modified single.php:

<?php
get_header();

 if (have_posts())
 {
 while (have_posts())  
 {
 art_page_navi();
 art_post();
 $ad_comment_count = get_comment_count($post->ID);
 if ($ad_comment_count['approved'] > 0) {
 echo "<div class="art-post">n";
 echo "<div class="art-post-body">n";
 echo "<script type="text/javascript"><!--n";
 echo "google_ad_client = "pub-8428018818545773";n";
 echo "/* ITRM-Middle-728x15, created 9/7/10 */n";
 echo "google_ad_slot = "0720805316";n";
 echo "google_ad_width = 728;n";
 echo "google_ad_height = 15;n";
 echo "//-->n";
 echo "</script>n";
 echo "<script type="text/javascript"n";
 echo "src="https://pagead2.googlesyndication.com/pagead/show_ads.js">n";
 echo "</script>n";
 echo "</div>n";
 echo "<div class='cleared'></div>n";
 echo "</div>n";
 }
 comments_template();
 }
 art_page_navi();
 } else {    
 art_not_found_msg();
 }

get_footer();

Basically we check if there are any comments and if the amount of approved comments is greater than 0 then we paste the AdSense for Content™ program code.

It is quite easy to have blend ads in with your site this way. You can also use this technique to have for example cu3er in your site. You can see that in action on Myrddin’s Shaman Blog.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.