Results 1 to 1 of 1

Thread: How to Add Adsense to Content in Drupal

Threaded View

  1. #1
    Join Date
    May 2009
    Location
    New York
    Posts
    3,772

    How to Add Adsense to Content in Drupal

    I didn't realize how hard this was going to be. It's easy to add adsense to a block within drupal. But to actually add the adsense within content is tricky.

    I found a solution for adding adsense to drupal pages. The great thing about the solution is that you can blend a 336x280 ad into the content with wrap around text wrap. You can place a couple of ads as well and the adsense unit will insert on the top and botton of the page.

    First, download, install and activate the adsense and contemplate modules.

    Second, create a php file with the code below and install to sites/all/contemplates/node-story-body.tpl.php
    Should you want the ads to appear on a blog then the file should be named node-blog-body.tpl.php

    Find the full instructions here

    Code:
     
    <?php
    $decoration1 = adsense_display(array('format' => '120x90', 'slot' => '4243067992'));
    $decoration2 = adsense_display(array('format' => '250x250', 'slot' => '0335368690'));
    $content = explode("</p>", $node->body);
    for ($i = 0; $i < count($content); $i++) {
      if ($i == 0 ) {
        ?> <div style="float:left;margin-right: 5px;"> <?php 
        print $decoration1;
        ?> </div> <?php
      }
      if ($i == 1) {
        ?> <div style="float:right;margin-left: 5px;"> <?php 
        print $decoration2;
        ?> </div> <?php
      }
      print $content[$i] . "</p>";
    }
    ?>
    Last edited by bogart; 26 November, 2009 at 20:57 PM.

Similar Threads

  1. Replies: 0
    Last Post: 17 January, 2010, 20:39 PM
  2. Replies: 7
    Last Post: 12 April, 2009, 09:08 AM
  3. Ratio of AdSense ads to content
    By keynes in forum AdSense
    Replies: 1
    Last Post: 11 April, 2009, 05:34 AM
  4. [WTB] Original Content Sites With AdSense Income
    By Ajeet in forum Sites
    Replies: 3
    Last Post: 19 March, 2009, 19:33 PM
  5. Adsense for Content Bug
    By Shenron in forum AdSense
    Replies: 2
    Last Post: 7 March, 2009, 18:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •