post_content; } if(!$ad_post) { //Get all ads $args = array('post_type' => 'adherder_ad', 'post_status' => 'publish', 'numberposts' => -1); $ad_posts = get_posts($args); $options = get_option('adherder_options'); if(count($ad_posts)>0){ $uid = $_COOKIE['ctopt_uid']; //calculate wait of the ads $weights = array(); foreach($ad_posts as $ad_post) { $converted = adherder_database_has_converted($uid, $ad_post->ID); if($converted) { $weights[] = $options['converted_weight']; } else { $seen = adherder_database_has_seen($uid, $ad_post->ID, $options['seen_limit']); if($seen) { $weights[] = $options['seen_weight']; } else { $weights[] = $options['normal_weight']; } } } //select random ad $num = mt_rand(0, array_sum($weights)); $i = 0; $n = 0; while($i < count($ad_posts)) { $n += $weights[$i]; if($n >= $num) { break; } $i++; } $ad_post = $ad_posts[$i]; // http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query setup_postdata($ad_post); $ad_id = $ad_post->ID; $ad_content = $ad_post->post_content; } else { // no calls yet $ad_id = -1; $ad_content = "You still need to define some Ads before they can be displayed."; } } return '