Looking foe Wordpress ad plugin.

Discussion in 'WordPress' started by Wulkanen, Jun 4, 2011.

  1. #1
    Hey there everyone.

    Does anyone know a plugin for Wordpress that enables me to
    automatically insert an AdSense ad in the middle og my articles?

    I have found a few, but they all seem to have problems.
    As I said, the plugin needs to be able to insert the ad in the middle
    or after a set amount of sentences.

    Thanks!

    Note: I know I misspelled the title... argh..
     
    Wulkanen, Jun 4, 2011 IP
  2. infogle

    infogle Prominent Member

    Messages:
    2,732
    Likes Received:
    128
    Best Answers:
    1
    Trophy Points:
    300
    #2
    You have to do a bit of coding...

    Open your “single.php” file (in your template folder)

    Search:
    <?php the_content(); ?>
    PHP:
    Replace with:
    01	<?php
    02	  $content = apply_filters('the_content', $post->post_content);  //get the post content store in $content
    03	  $save = explode("</p>", $content);  //Separate the content into <p> blocks
    04	  $tcount=0; //this is count for number of <p> blocks
    05	  $adon=0;  //this is a variable so you don't show ads more than once.
    06	  foreach($save as $item) {
    07	    echo $item;  //print the <p> block
    08	    echo "</p>";
    09	    if(preg_match('/<p> /',$item)==0 && $tcount>=1 && $adon==0) {
    10	                                $adon=1;
    11	?>
    12	ADSENSE HERE
    13	<?php
    14	    }
    15	 if(preg_match('/<p> /',$item)==0 && $tcount>=4 && $adon==1) {
    16	                                $adon=2;
    17	?>
    18	ANOTHER ADSENSE IF YOUR POST HAVE MORE THEN 4 PARAGRAPHS
    19	<?php
    20	   }
    21	   $tcount++;
    22	 }
    23	?>
    PHP:
    Hope it helps...
     
    infogle, Jun 4, 2011 IP
  3. Wulkanen

    Wulkanen Well-Known Member

    Messages:
    2,429
    Likes Received:
    47
    Best Answers:
    3
    Trophy Points:
    175
    #3
    Thanks I will set up a test site and try it, but does it slow down the loading speed much?
     
    Wulkanen, Jun 4, 2011 IP
  4. infogle

    infogle Prominent Member

    Messages:
    2,732
    Likes Received:
    128
    Best Answers:
    1
    Trophy Points:
    300
    #4
    Nothing at all.. all will work the normal way as previous - its just that you split your content in parts to place advertisement codes... that it

    hope it helps...
     
    infogle, Jun 4, 2011 IP