I’ve been trying to figure this out and I’m still not sure how to do it. How I’ve set it up so far is to have the main loop get all the posts, then a second loop get posts from the Ad category. I’m using this website’s tutorial to add the ads between the posts on the index page: https://www.howtostartablog.com/how-to-put-ads-in-between-my-posts.php
I’ve replaced the part where I’d input the AdSense code with:
<?php include(TEMPLATEPATH . '/includes/advertisements.php'); ?>
To include the advertisements, and all this is working fine.
However, I’m getting stuck on how to set up the query for the my advertisements include. So far I have this:
<div class="entry small" style="padding-top:2px;height:310px;">
<?php $my_query = new WP_Query( "cat=84" );
if ( $my_query->have_posts() ) {
while ( $my_query->have_posts() ) {
$my_query->the_post();
the_content();
}
}
wp_reset_postdata();
?>
</div><!-- end .entry -->
This is outputting post content from posts in the Ad category, which is perfect. But, the problem is that I only want to get one ad per case statement and I don’t want to duplicate the add. Currently, the loop will get all posts in the Ad category and also will duplicate them.
Or is this just the wrong way to set it up, because currently the ads only show on the index page, but eventually I also want them to show on category pages.
Any help will be appreciated!