Title: code every third post
Last modified: August 30, 2016

---

# code every third post

 *  [rizzler](https://wordpress.org/support/users/rizzler/)
 * (@rizzler)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/code-every-third-post/)
 * I have the following code, where in wordpress do i add it to make it work for
   every third post?
 * <?php
 * $counter = 1;
 * while ( have_posts() ) : the_post();
 * get_template_part( ‘content’, get_post_format() );
 * if( $counter === 3 ) { ?>
    <div class=”third-div-in-loop”>content</div> <?php}
 * $counter++;
 * endwhile;

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [OshikErnst](https://wordpress.org/support/users/oshikernst/)
 * (@oshikernst)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/code-every-third-post/#post-6642159)
 * It depends where you want it.
 * homepage – usually index.php or home.php (depends which theme you are using)
 * Oshik
 *  Thread Starter [rizzler](https://wordpress.org/support/users/rizzler/)
 * (@rizzler)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/code-every-third-post/#post-6642162)
 * Yes it’s om the homepage, index.php but where in the code. after what do i add
   it ?
 *  [OshikErnst](https://wordpress.org/support/users/oshikernst/)
 * (@oshikernst)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/code-every-third-post/#post-6642163)
 * send a link and i will tell you
 * usually its in the content section
 *  Thread Starter [rizzler](https://wordpress.org/support/users/rizzler/)
 * (@rizzler)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/code-every-third-post/#post-6642179)
 * here is my index file 🙂
 * [http://pastebin.com/jTNS6x5e](http://pastebin.com/jTNS6x5e)
 *  [OshikErnst](https://wordpress.org/support/users/oshikernst/)
 * (@oshikernst)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/code-every-third-post/#post-6642180)
 * You have to add:
    $counter = 1; before line 20 (<?php while(have_posts()) : the_post();?
   >)
 * and add this:
    if( $counter === 3 ) { ?> <div class=”third-div-in-loop”>content
   </div> <?php } $counter++;
 * before line 55 (<?php endwhile; ?>)
 *  Thread Starter [rizzler](https://wordpress.org/support/users/rizzler/)
 * (@rizzler)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/code-every-third-post/#post-6642287)
 * thanks a bunch! 🙂

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘code every third post’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 2 participants
 * Last reply from: [rizzler](https://wordpress.org/support/users/rizzler/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/code-every-third-post/#post-6642287)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
