I’m having some issues trying to insert Google Adsense codes between posts. First, have a look at the image below:
I have a grid of 12 posts on my homepage, each row containing 3 posts.
How could I put an Adsense ad on the second post of the first row, then another ad code as the same size of the full length of the container after the second row os posts, and then another ad at the 11th post.
I know it’s possible but i’m really struggling with it.
index.php
loop:
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php hct_content_nav( 'nav-below' ); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'hct' ); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'hct' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->
<?php endif; ?>
</div><!-- #content -->
And the content.php
code, which is called by index.php
:
<?php $count = $wp_query->current_post;
$c = fmod($count,3);
if ($c == '2') : ?>
<div style="clear:both;"></div>
This can be done by adding this before your
<?php endwhile; ?>
.This will display something (in this case your AD) after every 6th post