display adsense similar to DP?

Discussion in 'WordPress' started by Luq, Feb 7, 2010.

  1. #1
    I noticed in digitalpoint posts, adsense gets automatically displayed right in the middle of the post. I was wondering if it is possible to do this in wordpress posts as well via a plugin or otherwise.

    Thanks.
     
    Luq, Feb 7, 2010 IP
  2. Nei

    Nei Well-Known Member

    Messages:
    106
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    170
    #2
    You can insert adsense block anywhere in the wordpress template. What is the problem? :)
     
    Nei, Feb 7, 2010 IP
  3. Luq

    Luq Well-Known Member

    Messages:
    496
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    123
    #3

    I need to display it automatically in the middle of posts.
     
    Luq, Feb 7, 2010 IP
  4. Nei

    Nei Well-Known Member

    Messages:
    106
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    170
    #4
    Then you can try something like this:

    $s="I noticed in digitalpoint posts, adsense gets automatically displayed right in the middle of the post. I was wondering if it is possible to do this in wordpress posts as well via a plugin or otherwise.";
    $adsense='<br><br>ADSENSE HERE<br><br>';
    $arr=split(" ",$s);
    $words_count=sizeof ($arr);
    if ($words_count<2)
      echo("first part: ".substr($s,0,strlen($s)/2)).$adsense."second part: ".substr($s,strlen($s)/2);
    else 
      for ($i=0;$i<=$words_count;$i++) {
        echo $arr[$i].' ';
    	if ($i==floor($words_count/2-1)) echo $adsense;
      }
    PHP:
     
    Last edited: Feb 7, 2010
    Nei, Feb 7, 2010 IP
  5. Luq

    Luq Well-Known Member

    Messages:
    496
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    123
    #5
    Thanks for the code snippet, I will try it out and let you know how it goes, any particular file I should place it in?
     
    Luq, Feb 7, 2010 IP
  6. Nei

    Nei Well-Known Member

    Messages:
    106
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    170
    #6
    You should place it anywhere where you want to place the adsense block ;)
    This code only divides some string ($s) on two equal parts (by count of the words) and inserts the adsense block ($adsense) between these parts.
     
    Nei, Feb 7, 2010 IP
  7. Luq

    Luq Well-Known Member

    Messages:
    496
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    123
    #7
    hello,

    i set $s=<?php the_content(__('Read more'));?>; because that's where i need the adsense to be displayed in the middle of but the Adsense still displays right on top of the post.

    Any suggestions?

    Thanks in advance :)
     
    Luq, Feb 7, 2010 IP