Need Help [Wordpress] PHP code adsense under images

Discussion in 'WordPress' started by affnewbie, May 5, 2009.

  1. #1
    Hello All, I'm installed wordpress plugin called adsense under images.

    url:

    http://wordpress.org/extend/plugins/adsense-under-image/

    The description :

    Places specified Adsense code under the first image in a post. If there are no images no Adsense code will be insterted. Also the ads will only appear in single post pages.

    The question, How to set up the adsense appears after second images/third images. The default is after first images. and I think here's the code to detect img tag, its will insert adsense code automatically after first image, how to change that to become appears on second or third images? Thanks

    $adsense_code = $opt_val;

    $pattern = '/<img[^>]*>/';
    preg_match($pattern, $content, $matches);

    if(sizeof($matches)>0)
    {
    if(strstr($content,$matches[0]."</a>"))
    $content = str_replace($matches[0]."</a>",$matches[0]."</a>".$adsense_code,$content);
    else
    $content = str_replace($matches[0],$matches[0].$adsense_code,$content);
    }
    }

    return $content;
    }

    anyone can help me to modify?
     
    affnewbie, May 5, 2009 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That is the right section. Change the 0's to 1's, like this:

    if(sizeof($matches)>1)
    {
    if(strstr($content,$matches[1]."</a>"))
    $content = str_replace($matches[1]."</a>",$matches[1]."</a>".$adsense_code,$content);
    else
    $content = str_replace($matches[1],$matches[1].$adsense_code,$content);
    }

    This should put the Adsense code under the second image, if there is more than one image present.
    Use 2 instead of 1 if you want the Adsense code after the third image.
     
    Cash Nebula, May 9, 2009 IP