Forums

[Plugin: AdServe] Now supporting more then 1 ad per zone (2 posts)

  1. Hosting-WHSE
    Member
    Posted 11 months ago #

    Okay frustrated by the lack of more then 1 add per call i took it apon my self to rewrite small part of the code.

    in the ad.php

    now what you need to do is update how you call the banner
    <?php AdServe(3,"home"); ?> will server up a max of 3 random banners.

    if there is less matchs it will server all of them

    I did not test with the other method of embed it. post your feedback
    Jonathon

    replace the function ri_AdServe_GetBanner starts about line 151

    function iri_AdServe_GetBanner($quantity=1, $zone='' ) {
    	global $wpdb;
    	global $userdata;
    	$table_name = $wpdb->prefix . "adserve";
    	$ret="";
    	# get banner
    	$wherecond="((credits = -1) or (credits > 0)) AND (active = 1) AND (concat(keywords,' ') LIKE '%".$zone." %')";
    	$numrows = $wpdb->get_var("SELECT count(id) FROM $table_name WHERE $wherecond;");
    	if($numrows > 0) {
    		usleep(2000);
    		$bannum = array();
    		$temp = null;
    
    		if($numrows <= $quantity) {
    			$bannerIDs = $wpdb->get_results("SELECT * FROM $table_name WHERE $wherecond ");
    
    			$ret="\n\n<!-- Begin AdServe code -->\n";
    			shuffle($bannerIDs);
    			foreach($bannerIDs as $rk ) {
    
    				$ret.="<a target='_blank' href='".get_settings('siteurl')."/wp-content/plugins/wp-adserve/adclick.php?id=$rk->id' style='margin:0px;border:0px;'><img src='$rk->src' alt='$rk->title' /></a>";
    
    				get_currentuserinfo();
    				if($userdata->user_login != $rk->user) {
    					if($rk->credits > 0) {
    						$results = $wpdb->query( "update $table_name set credits=credits-1 where id=$rk->id" );
    					}
    					$results = $wpdb->query( "update $table_name set impressions=impressions+1 where id=$rk->id" );
    				}
    			}
    
    			$ret.="\n<!-- End AdServe code -->\n\n";
    
    		} else if($numrows >= $quantity) {
    			$bannerIDs = $wpdb->get_results("SELECT * FROM $table_name WHERE $wherecond order by rand() limit $quantity");
    			$ret="\n\n<!-- Begin AdServe code -->\n";
    
    			shuffle($bannerIDs);
    
    			foreach($bannerIDs as $rk ) {
    
    				$ret.="<a target='_blank' href='".get_settings('siteurl')."/wp-content/plugins/wp-adserve/adclick.php?id=$rk->id' style='margin:0px;border:0px;'><img src='$rk->src' alt='$rk->title' /></a>";
    
    				get_currentuserinfo();
    				if($userdata->user_login != $rk->user) {
    					if($rk->credits > 0) {
    						$results = $wpdb->query( "update $table_name set credits=credits-1 where id=$rk->id" );
    					}
    					$results = $wpdb->query( "update $table_name set impressions=impressions+1 where id=$rk->id" );
    				}
    			}
    
    			$ret.="\n<!-- End AdServe code -->\n\n";
    
    		} else {
    
    			$bannum = mt_rand(1, $numrows)-1;
    		    if ($bannum>=0) {
    				$rk = $wpdb->get_row("SELECT * FROM $table_name WHERE $wherecond LIMIT 1 OFFSET $bannum;");
    				$ret="\n\n<!-- Begin AdServe code : banner:$zone-$bannum/$numrows -->\n";
    				$ret.="<a target='_blank' href='".get_settings('siteurl')."/wp-content/plugins/wp-adserve/adclick.php?id=$rk->id' style='margin:0px;border:0px;'><img src='$rk->src' alt='$rk->title' /></a>";
    				$ret.="\n<!-- End AdServe code -->\n\n";
    				get_currentuserinfo();
    				if($userdata->user_login != $rk->user) {
    					if($rk->credits > 0) {
    						$results = $wpdb->query( "update $table_name set credits=credits-1 where id=$rk->id" );
    					}
    					$results = $wpdb->query( "update $table_name set impressions=impressions+1 where id=$rk->id" );
    				}
    			}
    		}
    	}
    	return $ret;
    }
  2. kremerdesign
    Member
    Posted 4 months ago #

    I know this is an old post, but I thought relevant to add to the discussion

    This is a solution to what I've been looking for, although it doesn't seem to correctly filter the zones. I know some php, but don't have the knowledge and time to figure out what isn't working. Not sure why. Any Thoughts?

    Here's a sample of my code in a sidebar:

    <div id="advertisements">
    <?php wp_reset_query(); ?>
    <?php if (is_front_page())
    { AdServe(3,"frontpage"); }
    else
    { AdServe(3,"otherpages"); }
    ?>
    </div>

Reply

You must log in to post.

About this Topic