WordPress.org

Ready to get started?Download WordPress

Forums

AdRotate
Insert Ads between posts and random groups (1 post)

  1. lonchbox
    Member
    Posted 8 months ago #

    I found a simple way to insert ads inside a Loop, and also rotate between two Groups.

    <?php
        $query = new WP_Query(array(
            'post_type' => array('post'),
    
        ));
    ?>
    <?php if ( $query->have_posts() ) : ?>
        <?php $_count = 1; ?>
    	<?php while ( $query->have_posts() ) : $query->the_post(); ?>
    		<?php get_template_part( 'partials', 'content' ); ?>
    
    		<?php if ($_count == 1) : ?>
    			<?php echo adrotate_group(rand(2,3)); ?>
    		<?php endif; $_count++; ?>
    
    	<?php endwhile; ?>
    <?php endif; ?>

    As you see in the code, the banners use the $_count to position the adrotate_group(), in this example the banners show in the second position.
    To show random two groups I use rand(2,3) inside the adrotate function where 2 & 3 are the ID of the groups I want to show in that position.

    Hope it helps :)

    http://wordpress.org/plugins/adrotate/

Reply

You must log in to post.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 8 months ago by lonchbox
  • This topic is not a support question
  • WordPress version: 3.6.1