3

I'm having some issues trying to insert Google Adsense codes between posts. First, have a look at the image below:

enter image description here

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>
Chun
  • 2,230
  • 5
  • 24
  • 46
Landowski
  • 27
  • 3
  • 1
    In order to answer this question, I think you'll need to provide some information about your css and the `grid` layout you are using. – Sam Mikes Jan 16 '15 at 12:56
  • I'm using this theme [link](http://hotclonethemes.com/preview/ssmag/), but modified to 3 posts per row through content.php (display the posts) and css (boxes width). – Landowski Jan 16 '15 at 16:17
  • Please, i just need a way to post an ad at specific places. I do know that is there a way to alter that php counter above to display ads at specific places, bu t i dont know how i do it. When i put a code from a example, the ad shows but, its not a post, then the counter break the line at the count of 3. But, with a ad in the middle of row 1, the count breaks at the third, leaving me with the layout: ROW 1: POST AD POST ROW 2: POST (ALONE) ---- COUNTER BREAKS AT THIRD --- ROW 3: POST POST POST – Landowski Jan 20 '15 at 16:14

1 Answers1

3

This can be done by adding this before your <?php endwhile; ?>.
This will display something (in this case your AD) after every 6th post

<?php $postnum++; if($postnum%6 == 0) { ?>
    ...DO SOMETHING..
<?php } ?>
Chun
  • 2,230
  • 5
  • 24
  • 46