/** * render the ads list * * @param $obj $group group object */ public function render_ads_list(Advanced_Ads_Group $group) { $ads = $this->get_ads($group); $weights = $group->get_ad_weights(); $weight_sum = array_sum($weights); $ads_output = $weights; arsort($ads_output); // The Loop if ($ads->have_posts()) { echo $group->type == 'default' && $weight_sum ? '<ul>' : '<ol>'; while ($ads->have_posts()) { $ads->the_post(); $line_output = '<li><a href="' . get_edit_post_link(get_the_ID()) . '">' . get_the_title() . '</a>'; $status = get_post_status(); switch ($status) { case 'future': $line_output .= '<i>(' . __('scheduled', ADVADS_SLUG) . ')</i>'; break; case 'pending': $line_output .= '<i>(' . __('pending', ADVADS_SLUG) . ')</i>'; break; } // check expiry date $ad = new Advanced_Ads_Ad(get_the_ID()); if (!$ad->can_display_by_expiry_date()) { $line_output .= '<i>(' . __('expired', ADVADS_SLUG) . ')</i>'; } $_weight = isset($weights[get_the_ID()]) ? $weights[get_the_ID()] : Advanced_Ads_Group::MAX_AD_GROUP_WEIGHT; if ($group->type == 'default' && $weight_sum) { $line_output .= '<span class="ad-weight" title="' . __('Ad weight', ADVADS_SLUG) . '">' . number_format($_weight / $weight_sum * 100) . '%</span></li>'; } $ads_output[get_the_ID()] = $line_output; } $ads_output = $this->remove_empty_weights($ads_output); echo implode('', $ads_output); echo $group->type == 'default' && $weight_sum ? '</ul>' : '</ol>'; if ($group->ad_count === 'all') { echo '<p>' . __('all published ads are displayed', ADVADS_SLUG) . '</p>'; } elseif ($group->ad_count > 1) { echo '<p>' . sprintf(__('up to %d ads displayed', ADVADS_SLUG), $group->ad_count) . '</p>'; } } else { _e('No ads assigned', ADVADS_SLUG); } // Restore original Post Data wp_reset_postdata(); }