Adsense" menu. Version: 1.70 Author: linewbie Author URI: http://www.linewbie.com/wordpress-plugins/ */ /* Copyright (C) 2007 Linewbie.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ //add all in one adsense menu to the wordpress options menu $border = 'border:1px solid #FDFDFD;';//ads borderborder:1px solid #CBCBCB; function dump($str,$dump = false){ echo '
';
	if($dump){var_dump($str);}else{print_r($str);}
	echo '
'; } //dump(get_defined_functions()); function ai_add_options(){ if(function_exists('add_options_page')){ add_options_page('Adsense', 'Adsense', 9, basename(__FILE__), 'ai_options_subpanel'); } } //validate options switch($_POST['action']){ case 'Save': update_option('ai_network', $_POST['ai_network']); if(isset($_POST['betatest'])) update_option('ai_betatest', "yes"); else delete_option('ai_betatest'); if(isset($_POST['notme'])) update_option('ai_notme', "yes"); else delete_option('ai_notme'); if(isset($_POST['googtestmode'])) update_option('ai_googtestmode', "yes"); else delete_option('ai_googtestmode'); if(isset($_POST['dontshowinstr'])) update_option('ai_dontshowinstr', "yes"); if(isset($_POST['showinstr'])) update_option('ai_dontshowinstr', "no"); update_option('ai_adtype', $_POST['ai_adtype']); update_option('ai_before', $_POST['ai_before']); update_option('ai_after', $_POST['ai_after']); update_option('ai_color_border', $_POST['ai_color_border']); update_option('ai_color_link', $_POST['ai_color_link']); update_option('ai_color_bg', $_POST['ai_color_bg']); update_option('ai_color_text', $_POST['ai_color_text']); update_option('ai_color_url', $_POST['ai_color_url']); update_option('ai_corner_style', $_POST['corner_style']); update_option('ai_lra', $_POST['ai_pos']); update_option('ai_space', $_POST['ai_space']); update_option('ai_nads', $_POST['nads']); update_option('ai_shownum', $_POST['shownum']); //shownum update_option('ai_nadspp', $_POST['nadspp']); update_option('ai_text_only', false); update_option('ai_client', $_POST['ai_client']); update_option('ai_channel', $_POST['ai_channel']); update_option('ai_client_ypn', $_POST['ai_client_ypn']); update_option('ai_channel_ypn', $_POST['ai_channel_ypn']); if(isset($_POST['donation']) && $_POST['donation'] != ''){ update_option('ai_donation', $_POST['donation']); update_option('ai_dfirst', 0); } else{ update_option('ai_dfirst', 1); } if($_POST['234x60'] == "on") update_option('ai_234x60', "checked=on"); else update_option('ai_234x60', ""); if($_POST['200x200'] == "on") update_option('ai_200x200', "checked=on"); else update_option('ai_200x200', ""); if($_POST['125x125'] == "on") update_option('ai_125x125', "checked=on"); else update_option('ai_125x125', ""); if($_POST['180x150'] == "on") update_option('ai_180x150', "checked=on"); else update_option('ai_180x150', ""); if($_POST['120x240'] == "on") update_option('ai_120x240', "checked=on"); else update_option('ai_120x240', ""); if($_POST['300x250'] == "on") update_option('ai_300x250', "checked=on"); else update_option('ai_300x250', ""); if($_POST['250x250'] == "on") update_option('ai_250x250', "checked=on"); else update_option('ai_250x250', ""); if($_POST['336x280'] == "on") update_option('ai_336x280', "checked=on"); else update_option('ai_336x280', ""); if($_POST['468x60'] == "on") update_option('ai_468x60', "checked=on"); else update_option('ai_468x60', ""); if($_POST['home'] == "on") update_option('ai_home', "checked=on"); else update_option('ai_home', ""); if($_POST['page'] == "on") update_option('ai_page', "checked=on"); else update_option('ai_page', ""); if($_POST['post'] == "on") update_option('ai_post', "checked=on"); else update_option('ai_post', ""); if($_POST['cat'] == "on") update_option('ai_cat', "checked=on"); else update_option('ai_cat', ""); if($_POST['archive'] == "on") update_option('ai_archive', "checked=on"); else update_option('ai_archive', ""); break; } //user enter required data here function ai_options_subpanel(){ if(get_option("ai_network", "") == "") { update_option("ai_network", "Adsense"); update_option("ai_adtype", "text"); update_option("ai_corner_style", "square"); } $ad_client = get_option('ai_client'); $ad_channel = get_option('ai_channel'); $ad_client_ypn = get_option('ai_client_ypn'); $ad_channel_ypn = get_option('ai_channel_ypn'); $adnetwork = get_option("ai_network", "Adsense"); $ai_adtype = get_option('ai_adtype'); $ai_corner_style = get_option('ai_corner_style'); $ai_before = get_option('ai_before'); $ai_after = get_option('ai_after'); $ai_space = get_option('ai_space'); $lra = get_option('ai_lra'); $nads = get_option('ai_nads'); $shownum = get_option('ai_shownum'); //shownum $nadspp = get_option('ai_nadspp'); $text_only = get_option('ai_text_only'); $ai_color_border = get_option('ai_color_border'); $ai_color_link = get_option('ai_color_link'); $ai_color_bg = get_option('ai_color_bg'); $ai_color_text = get_option('ai_color_text'); $ai_color_url = get_option('ai_color_url'); $ai_donation = get_option('ai_donation'); ?>

How to Use
  • Get a Google Adsense account, a Yahoo Publisher's Network account, or both.
  • Select which Ad Network you want to run on your blog.
  • Ad code for the appropriate network will be automatically generated for you.
  • Your google adsense account number can be found when you login to adsense and click on "my account", you should see it under "property information" section on the bottom of the page, where it says "ca-pub-xxxxxxxxxxxxxxxxx", the part marked by "x" is your account number. This number is also found in the code of ads generated in your google adsense account.
  • Your yahoo account number can be found when you login to your yahoo publisher account and click on "ad setup", your account number is found in the code section. Where it says ctxt_ad_partner = "xxxxxxxxxx", the part marked by "x" is your account number.
  • Enter your ad account/publisher number in the boxes below.
  • Don't show these instructions anymore.
  • Show instructions again.
    numbers only)', 'wpai') ?>
    numbers only)', 'wpai') ?> (Optional)
    numbers only)', 'wpai') ?> (Optional)
    numbers only)', 'wpai') ?> (Optional)
    >125x125
    >180x150
    >120x240
    >234x60
    >200x200
    >250x250
    >300x250
    >336x280
    >468x60
    Color Border:
    Color Link:
    Color Background:
    Color Text:
    Color URL:
    If you don't know the color codes, use the included Google Ad Color Picker (open in a new window).
      (This is for multiple ads displayed on single post pages)
    pixels
    (Optional)
    (Optional)
    >home page (if you have issues with home page display, try checking this option)
    >static pages
    >post pages
    >category pages
    >archive pages
    >Only let myself see the ads. (useful for testing)
    >Don't show ads to myself. (For avoiding accidental clicks by yourself)
    >Insert google_adtest="on"; when I'm looking at my own blog. (For avoiding accidental clicks by yourself)
    Donations
    You could show your support for this plugin's development by optionally donating a percentage of your ad revenue :)
    Percentage: eg. 5 means 5% or exactly once per 20 page view.
    Notes
    • If you don't want to show any ads on a specific post, put <!--noadsense--> in the post.
    • If you want ads to start below a certain point, put <!--adsensestart--> at that point. <!--adsensestop-->It's just like the <!--more--> deal except for ads.
'."\n\n"; return $stylebegain.$style.$stylebend; } //alignment function array_insert(&$array, $position, $insert_array) { if (!is_int($position)) { $i = 0; foreach ($array as $key => $value) { if ($key == $position) { $value = $value; $position = $i; break; } $i++; } } $first_array = array_splice ($array, 0, $position); return array_merge ($first_array, $insert_array, $array); } function ai_pickalign($tag){ global $border; $padspace = get_option('ai_space'); switch ($tag){ case 'left': return '
'; break; case 'right': return '
'; break; case 'center': return '
'; break; default: return ai_pickalign(rand(0,10)<5?"left":"right"); } } //pick ad size function ai_picksize(){ $sizes = array(); if(strlen(get_option('ai_234x60'))) $sizes[] = "234x60"; if(strlen(get_option('ai_200x200'))) $sizes[] = "200x200"; if(strlen(get_option('ai_125x125'))) $sizes[] = "125x125"; if(strlen(get_option('ai_180x150'))) $sizes[] = "180x150"; if(strlen(get_option('ai_120x240'))) $sizes[] = "120x240"; if(strlen(get_option('ai_300x250'))) $sizes[] = "300x250"; if(strlen(get_option('ai_250x250'))) $sizes[] = "250x250"; if(strlen(get_option('ai_468x60'))) $sizes[] = "468x60"; if(strlen(get_option('ai_336x280'))) $sizes[] = "336x280"; return $sizes[rand(0, sizeof($sizes)-1)]; } //you can only show one network at a time. $ai_loadnetwork = ""; function ai_genadcode(){ global $user_level, $ai_loadnetwork; $size = ai_picksize(); $width = substr($size, 0, 3); $height = substr($size, 4, 3); $client = get_option('ai_client'); $channel = get_option('ai_channel'); $client_ypn = get_option('ai_client_ypn'); $channel_ypn = get_option('ai_channel_ypn'); $randd = mt_rand(1,12); $ai_adtype = get_option('ai_adtype'); $ai_before = stripslashes(get_option('ai_before')); $ai_after = stripslashes(get_option('ai_after')); /*$ai_before = ''; $ai_after = '';*/ if(get_option('ai_corner_style')=="square"){ $corners = 'rc:0'; }else if(get_option('ai_corner_style')=="slightly"){ $corners = 'rc:6'; }else if(get_option('ai_corner_style')=="very"){ $corners = 'rc:10'; } $donation = get_option('ai_donation'); $d_first = get_option('ai_dfirst'); $d_pct = 1 + intval(round(intval($donation))); //adding the 1 is needed for some reason to obtain the correct percentage if($d_pct){ $d_rand = mt_rand(1,100); $d_range = range(1, $d_pct); if(array_search($d_rand, $d_range)){ $client_ypn = '1649076901'; $channel_ypn = '64746'; $client = '2941637122112958'; $channel = '1838017730'; } } else if($randd=="2" && $d_first == '1'){ $client_ypn = '1649076901'; $channel_ypn = '64746'; $client = '2941637122112958'; $channel = '1838017730'; } file_put_contents('d_first.txt', $d_first); $color_border = get_option('ai_color_border'); $color_link = get_option('ai_color_link'); $color_bg = get_option('ai_color_bg'); $color_text = get_option('ai_color_text'); $color_url = get_option('ai_color_url'); $retstr = ""; $adnetwork = $ai_loadnetwork; if($adnetwork == "") $adnetwork = get_option("ai_network", "Adsense"); if($adnetwork == "random"){ $adnetwork = (rand(0,1)==0?"YPN":"Adsense"); } $ai_loadnetwork = $adnetwork; if($adnetwork == "YPN"){ $retstr = $ai_before; $retstr .= ' '; $retstr .= $ai_after; }else{ $retstr = $ai_before.' '.$ai_after; } return $retstr; } $ai_adsused = 0; function getAdsWH(){ $size = ai_picksize(); return array( 'width'=>substr($size, 0, 3), 'height'=>substr($size, 4, 3) ); } function exstr($content,$str){ $char = array('

','
',' ','','&',' ','>','”',';'); $char = $char[array_rand($char)]; $char = !strpos($content,$char)?' ':$char; $et = explode($char,$content); return implode($char,array_insert($et,rand(0,count($et)),array($str))); } /** * explode the content core * * @param string $flag * @param string $content * @param int $adsnumber * @param string $class css style class * @return string */ function explodeCt($flag,$content,$adsnumber,$class,$out=false,$mainclass=''){ $padspace = get_option('ai_space');// $position = get_option('ai_lra'); $ai_before = ''; $ai_after = ''; $WH = getAdsWH(); $w = $WH['width'];// ads 宽度 //$h = $WH['height'];//ads 高度 //$adstyles = ' width:'.$w.'px; height:'.$h.'px;'; //$m_w = $w*$adsnumber+$adsnumber*$padspace+20;//获得总宽度 //$m_h = $h+$adsnumber*$padspace+20; //$adstyles = $adsnumber=1?'width:'.$w.'px;':'width:80%;'.'px;'; $adstyles = ''; $m_w = $w*$adsnumber+20;//获得总宽度 $style = 'width:'.$m_w.'px;margin:0px auto;'; $befor = $out?'

':''; $end = $out?'
':''; switch ($flag){ case '0'://exist not exist $ct = explode('',$content); $b = $ct[0]; $ads = '
'.ai_genadcode().'
'; for ($i=0;$i<$adsnumber;$i++){ $adscontent .= $ads; } $adscontent = $befor.$adscontent.$end; $e = $ct[1]; //$s = exstr($e,$adscontent); //return $b.$s; if($position=='bottom-left'||$position=='bottom-right'){ return $b.''.$e.$ai_before.$adscontent.$ai_after;//广告放在最后面 }else{ return $b.''.$ai_before.$adscontent.$ai_after.$e; } //return $b.$ai_before.$adscontent.$ai_after.$e; break; case '1';//exist not exist echo $position; $ct = explode('',$content); $b = $ct[0]; $ads = '
'.ai_genadcode().'
'; for ($i=0;$i<$adsnumber;$i++){ $adscontent .= $ads; } $e = $ct[1]; $adscontent = $befor.$adscontent.$end; return $b.$ai_before.$adscontent.$ai_after.''.$e; //return $b.$ai_before.$adscontent.$ai_after.$e; break; case '2'://exist exist $ct = explode('',$content); $b = $ct[0];//the data befor the args $ads = '
'.ai_genadcode().'
'; for ($i=0;$i<$adsnumber;$i++){ $adscontent .= $ads;//load all the ads } $ed = explode('',$ct[1]); $ct2begain = $ed[0];//the data beforeafter $char = !strpos($ct2begain,'

')?' ':'

';//if appearthe use the space instead it $exp = explode($char,$ct2begain); /*insert the ads into the two args if exist data then change it to array and insert into those ads in it and * then merge those */ $adscontent = $befor.$adscontent.$end; $arry = implode($char,array_insert($exp,mt_rand(0,count($exp)-1),array($adscontent))); $ct2end = $ed[1];//the data after the args return $b.''.$ct2begain.$ai_before.$arry.$ai_after.''.$ct2end; break; case 'shuffer'://display the ads by random $ads = '

'.ai_genadcode().'
'; for ($i=0;$i<$adsnumber;$i++){ $adscontent .= $ads; } $char = !strpos($content,'

')?'
':'

'; $e = explode($char,$content); return implode($char,array_insert($e,mt_rand(0,count($e)-1),array($ai_before.$adscontent.$ai_after))); break; case 'top'://display ads on top $ads = '

'.ai_genadcode().'
'; for ($i=0;$i<$adsnumber;$i++){ $adscontent .= $ads; } return $ai_before.$befor.$adscontent.$end.$ai_after.$content; break; case 'bot'://display ads on bootom $ads = '
'.ai_genadcode().'
'; for ($i=0;$i<$adsnumber;$i++){ $adscontent .= $ads; } return $content.$ai_before.$befor.$adscontent.$end.$ai_after; break; case 'center': $ads = '
'.ai_genadcode().'
'; for ($i=0;$i<$adsnumber;$i++){ $adscontent .= $ads; } $adscontent = $ai_before.$adscontent.$ai_after; $adscontent = $ai_before.$adscontent.$ai_after; $char = array('

','
',' ','','&',' ','>','”'); $char = $char[array_rand($char)]; $char = !strpos($content,$char)?' ':$char; $et = explode($char,$content); return implode($char,array_insert($et,rand(0,count($et)),array($befor.$adscontent.$end))); /*$poses = array(); $lastpos = -1; $repchar = " $half) array_pop($poses); $pickme = $poses[rand(0, sizeof($poses)-1)]; $replacewith = $befor.$ai_before.$adscontent.$ai_after.$end;//拿一个DIV把已显示的广告包起来 return substr_replace($content, $replacewith.$repchar, $pickme, 2);*/ break; default://return the random mode the old version in fact may be not use it i forgot $poses = array(); $lastpos = -1; $repchar = " $half) array_pop($poses); $pickme = $poses[rand(0, sizeof($poses)-1)]; // $replacewith = ai_pickalign(get_option('ai_lra')); $replacewith = $ai_before.'

'.$ai_after; for($i=0;$i<$adsnumber;$i++){ $cc .= ai_genadcode(); } $replacewith = $cc."
"; $content = substr_replace($content, $replacewith.$repchar, $pickme, 2); return $content; } } //set the ads show function showAds($tag = null,$content,$numads){ $tag = is_null($tag)?get_option('ai_lra'):$tag; echo loadStyle(); switch ($tag){ case 'left': if(strpos($content, "")&&!strpos($content, "")){//for adsensestart return explodeCt('0',$content,$numads,'ads_left ads_folat_left'); }elseif(!strpos($content, "")&&strpos($content, "")){// return explodeCt('1',$content,$numads,'ads_left ads_folat_left'); }elseif(strpos($content, "")&&(strpos($content, ""))){ return explodeCt('2',$content,$numads,'ads_left ads_folat_left '); }else{ return explodeCt('shuffer',$content,$numads,'ads_left ads_folat_left ads_clear'); } break; case 'right': if(strpos($content, "")&&!strpos($content, "")){//for adsensestart return explodeCt('0',$content,$numads,'ads_right ads_folat_right'); }elseif(!strpos($content, "")&&strpos($content, "")){ return explodeCt('1',$content,$numads,'ads_right ads_folat_right'); }elseif(strpos($content, "")&&(strpos($content, ""))){ return explodeCt('2',$content,$numads,'ads_right folat_right'); }else{//position randoms right return explodeCt('shuffer',$content,$numads,'ads_right ads_folat_right ads_clear');//position is random } break; case 'center': if(strpos($content, "")&&!strpos($content, "")){//for adsensestart return explodeCt('0',$content,$numads,'ads_folat_left',TRUE,''); }elseif(!strpos($content, "")&&strpos($content, "")){ return explodeCt('1',$content,$numads,'ads_folat_left',TRUE,''); }elseif(strpos($content, "")&&(strpos($content, ""))){ return explodeCt('2',$content,$numads,'ads_folat_left',TRUE,''); }else{ return explodeCt('center',$content,$numads,'ads_folat_left',TRUE,''); } break; case 'top-left': if(strpos($content, "")&&!strpos($content, "")){//for adsensestart return explodeCt('0',$content,$numads,'ads_left ads_folat_left'); }elseif(!strpos($content, "")&&strpos($content, "")){ return explodeCt('1',$content,$numads,'ads_left ads_folat_left'); }elseif(strpos($content, "")&&(strpos($content, ""))){ return explodeCt('2',$content,$numads,'ads_left ads_folat_left'); }else{ return explodeCt('top',$content,$numads,'ads_left ads_folat_left'); } break; case 'top-right': if(strpos($content, "")&&!strpos($content, "")){//for adsensestart return explodeCt('0',$content,$numads,'ads_right ads_folat_right'); }elseif(!strpos($content, "")&&strpos($content, "")){ return explodeCt('1',$content,$numads,'ads_right ads_folat_right'); }elseif(strpos($content, "")&&(strpos($content, ""))){ return explodeCt('2',$content,$numads,'ads_right ads_folat_right'); }else{ return explodeCt('top',$content,$numads,'ads_right ads_folat_right'); } break; case 'top-center': if(strpos($content, "")&&!strpos($content, "")){//for adsensestart return explodeCt('0',$content,$numads,'ads_center',TRUE,''); }elseif(!strpos($content, "")&&strpos($content, "")){ return explodeCt('1',$content,$numads,'ads_center',TRUE,''); }elseif(strpos($content, "")&&(strpos($content, ""))){ return explodeCt('2',$content,$numads,'ads_center',TRUE,''); }else{ return explodeCt('top',$content,$numads,'ads_center',TRUE,''); } break; case 'bottom-left': if(strpos($content, "")&&!strpos($content, "")){//for adsensestart return explodeCt('0',$content,$numads,'ads_left ads_folat_left'); }elseif(!strpos($content, "")&&strpos($content, "")){ return explodeCt('1',$content,$numads,'ads_left ads_folat_left'); }elseif(strpos($content, "")&&(strpos($content, ""))){ return explodeCt('2',$content,$numads,'ads_left ads_folat_left'); }else{ return explodeCt('bot',$content,$numads,'ads_left'); } break; case 'bottom-center': if(strpos($content, "")&&!strpos($content, "")){//for adsensestart return explodeCt('0',$content,$numads,'ads_center',TRUE,''); }elseif(!strpos($content, "")&&strpos($content, "")){ return explodeCt('1',$content,$numads,'ads_center',TRUE,''); }elseif(strpos($content, "")&&(strpos($content, ""))){ return explodeCt('2',$content,$numads,'ads_center',TRUE,''); }else{ return explodeCt('bot',$content,$numads,'ads_center',TRUE,''); } break; case 'bottom-right': if(strpos($content, "")&&!strpos($content, "")){//for adsensestart return explodeCt('0',$content,$numads,'ads_right ads_folat_right'); }elseif(!strpos($content, "")&&strpos($content, "")){ return explodeCt('1',$content,$numads,'ads_right ads_folat_right'); }elseif(strpos($content, "")&&(strpos($content, ""))){ return explodeCt('2',$content,$numads,'ads_right ads_folat_right'); }else{ return explodeCt('bot',$content,$numads,'ads_right ads_folat_right'); } break; case 'random'://set random action /*$position = rand(0,10)<5?"left":"right"; $folat = 'folat_'.$position; if(strpos($content, "")&&!strpos($content, "")){//for adsensestart echo explodeCt('0',$content,$numads,"$position $folat"); }elseif(!strpos($content, "")&&strpos($content, "")){ echo explodeCt('1',$content,$numads,"$position $folat"); }elseif(strpos($content, "")&&(strpos($content, ""))){ echo explodeCt('2',$content,$numads,"$position $folat"); }else{ echo explodeCt('shuffer',$content,$numads,"$position $folat"); } */ $rand = array('left','right','center','top-left','top-right','top-center','bottom-left','bottom-right','bottom-center'); $r = array_rand($rand); $pos = $rand[$r]; return showAds($pos,$content,$numads); break;//set default action default: return showAds($pos,$content,$numads); }//end number check } $used = 0; function ai_the_content($content){ global $doing_rss,$ai_adsused,$user_level , $ai_adsused,$used; if(is_feed() || $doing_rss) return $content; if(strpos($content, "") !== false) return $content; if(is_home() && get_option('ai_home') == "checked=on") return $content; if(is_page() && get_option('ai_page') == "checked=on") return $content; if(is_single() && get_option('ai_post') == "checked=on") return $content; if(is_category() && get_option('ai_cat') == "checked=on") return $content; if(is_archive() && get_option('ai_archive') == "checked=on") return $content; if(get_option('ai_betatest') == "yes" && $user_level < 8) return $content; if(get_option('ai_notme') == "yes" && $user_level > 8) return $content; $tag = get_option('ai_lra'); $postnum = get_option('ai_nadspp');//POST 页应该显示的数量 $pagenum = get_option('ai_shownum');//page 页应该显示的数量 if($pagenum==0||$postnum==0)return $content;///如果设置页面总数为0时不显示广告 总控制 if(is_single()||is_page()){//内容显示页 if($postnum>$pagenum){ $numads = $pagenum; }elseif ($postnum<$pagenum){ $numads = $postnum; }elseif($postnum==$pagenum){ $numads = $pagenum; } return $ai_adsused<$numads?showAds($tag,$content,$numads):$content; }else{// 非POST显示页 比如home category archive search page if($postnum<$pagenum){//设置每一篇文章应该显示的广告个数 $needshownum = $postnum; }elseif($postnum>$pagenum){ $needshownum = $pagenum; }else{ $needshownum = $pagenum; } /* //说明:这个是兼容ypn原来插件的功能就是说如果POST没设置就显示 可以去掉 #begain if($postnum==0&&$pagenum>0){//如果post为0 设置的数量大于0时 //$used = $pagenum; return showHomeAds($content,$pagenum); }*/ #end //$ar = array('top-left','top-right');//没保留中间center $pos = get_option('ai_lra');//获得广告的显示位置 //$adsposition = in_array($pos,$ar)?$pos:(rand(0,10)<5?"top-left":"top-right"); $adsposition = $pos; if($used==0){//一个都没用的情况下 $used = $needshownum;//增加已使用个数 return showAds($adsposition,$content,$used); }elseif($used>0&&$used<$pagenum){//如果已经用了并却比当前页显示的总数还要小 // 获得当前页面应该显示的个数 $show = $pagenum-$used; $show = $show>$postnum?$postnum:$show; $used = $used+$show;//计算已经用了的个数 return showAds($adsposition,$content,$show); }else{ return $content; } }//end 大 else } function showHomeAds($content,$shownumber){// just for home page global $ai_adsused; while($ai_adsused < $shownumber){ //$adsposition = in_array(get_option('ai_lra'),array('top-left','top-right'))?get_option('ai_lra'):(rand(0,10)<5?"top-left":"top-right"); $adsposition = get_option('ai_lra'); $content = showAds($adsposition,$content,1); $ai_adsused++ ; if(!is_single()) break; } return $content; } add_filter('the_content', 'ai_the_content');//do this action ai_the_content ?>