Plugin Directory

Changeset 1709761


Ignore:
Timestamp:
08/07/2017 06:43:47 PM (9 years ago)
Author:
shahalom
Message:

Display specific number of ads mentioned in the widget or in the limit attribute of shortcode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • monetize-me/trunk/main.php

    r1709597 r1709761  
    9393       $width = intval($atts['width']);
    9494       $stype = msbd_sanitization($atts['stype']);
     95       $limit = (intval($atts['limit']) > 0) ? intval($atts['limit']) : 1;
    9596
    9697        if ($width<1) {
     
    113114            ),
    114115
    115             'posts_per_page' => intval( $atts['limit'] ),
     116            'posts_per_page' => intval( $limit ),
    116117            'orderby'        => 'rand',
    117118        );
     
    153154        //print_r($args);
    154155        //exit;
     156
     157
     158        ob_start();
     159
    155160        $ads = new WP_Query( $args );
    156161
    157         ob_start();
    158         if( $ads->have_posts()) {
     162        $servable_ads = array();
     163        $servable_ad_count = 0;
     164
     165        if ($ads->have_posts()) {
    159166            while( $ads->have_posts()) {
    160167                $ads->the_post();
    161                 if ($atts['wrapper']==1) {
    162                     echo '<div class="ads-section'.msbd_asf($atts['class']).'">'.get_the_content().'</div>';
    163                 } else {
    164                     echo get_the_content();
    165                 }
     168
     169                $servable_ad_count++;
     170                $servable_ads[] = get_the_content();
    166171
    167172                $count_view = intval( get_post_meta(get_the_ID(), 'mmp_count_view', true) );
    168173                $count_view++;
    169174                update_post_meta(get_the_ID(), 'mmp_count_view', $count_view);
     175
     176                if ($servable_ad_count>=$limit) {
     177                    break;
     178                }
    170179            }
     180
     181            for ($x = $servable_ad_count; $x<$limit; $x++) {
     182                $servable_ad = $servable_ads[0];
     183                $servable_ads[] = $servable_ad;
     184            }
     185        }
     186
     187        if ($atts['wrapper']==1) {
     188            echo '<div class="ads-section'.msbd_asf($atts['class']).'">'.implode("", $servable_ads).'</div>';
     189        } else {
     190            echo implode("", $servable_ads);
    171191        }
    172192
     
    174194
    175195        return ob_get_clean();
     196
    176197    }
    177198} // End of Class Main
Note: See TracChangeset for help on using the changeset viewer.