If you're looking to display ads on your site, one of the best places to do it is mixed up with your main content. This will cause visitors to view your ads, as they're engaged with your work, often resulting in higher click-through rates and better paydays for you.
First, open the template in which you wish to display advertisements while iterating over the available posts. This will most likely be a listing template file like index.php
or category.php
. Decide on the number of posts that you wish to display between advertisements. Place your cursor where you want your loop to appear, and then insert the following code:
<?php if( have_posts() ) { $ad_counter = 0; $after_every = 3; while( have_posts() ) { $ad_counter++; the_post(); ?> <h2><?php the_title(); ?></h2> <?php // Display ads $ad_counter = $ad_counter % $after_every; if( 0 == $ad_counter ) { echo '<h2 style="color:red;">Advertisement</h2>...