Insert Ads between posts and random groups
-
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
$_countto position theadrotate_group(), in this example the banners show in the second position.
To show random two groups I userand(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 🙂
The topic ‘Insert Ads between posts and random groups’ is closed to new replies.