Title: Put some html code after third item in the loop
Last modified: August 21, 2016

---

# Put some html code after third item in the loop

 *  [zecke](https://wordpress.org/support/users/zecke/)
 * (@zecke)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/put-some-html-code-after-third-item-in-the-loop/)
 * Hi, so I got code that displays all post in current category right here:
 *     ```
       <ul>
       <?php foreach((get_the_category($post->ID)) as $category) { ?>
   
       <?php $catVal = $category->cat_ID; }
          $IDOutsideLoop = $post->ID;
          global $post;
       $myposts = get_posts('category='.$catVal.'&numberposts=999&order=ASC');
          foreach ($myposts as $post) { ?>
            <li<?php if($IDOutsideLoop == $post->ID) { echo " class=\"current\""; } ?>>
            <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
       <?php }; ?>
       </ul>
       ```
   
 * All I need is to echo some html code only after 3 item from the loop. I`m not
   a php guy, so please If You be so kind and give me ready and workind code I will
   be delighted. Thank You.
 * Rafał

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

 *  [Jesin A](https://wordpress.org/support/users/jesin/)
 * (@jesin)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/put-some-html-code-after-third-item-in-the-loop/#post-4178447)
 * Try this
 *     ```
       <ul>
       <?php foreach((get_the_category($post->ID)) as $category) { ?>
   
       <?php $catVal = $category->cat_ID; }
          $IDOutsideLoop = $post->ID;
          $i=0;
          global $post;
       $myposts = get_posts('category='.$catVal.'&numberposts=999&order=ASC');
          foreach ($myposts as $post) { ?>
            <li<?php if($IDOutsideLoop == $post->ID) { echo " class=\"current\""; } ?>>
            <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
       <?php $i++; if($i==3) { echo 'your html code'; } }; ?>
       </ul>
       ```
   
 *  Thread Starter [zecke](https://wordpress.org/support/users/zecke/)
 * (@zecke)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/put-some-html-code-after-third-item-in-the-loop/#post-4178697)
 * And I got another problem with the same code and I can`t figure it out.
 * I need to change this code to show only 3 first items from the loop. Then after
   those 3 items I need something like “read more” link and after clicking that 
   I want to get rest of the loop.
 * Of course even wihtout clicking “read more” all items from the loop suppose to
   be visible in source code for bots to indexing.
 * If You know how to help me, do not hesistate 🙂
    Thanks btw. I`m in love with
   WordPress
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/put-some-html-code-after-third-item-in-the-loop/#post-4178698)
 * Please post a new topic about this.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/put-some-html-code-after-third-item-in-the-loop/#post-4178699)
 * That won’t happen in this case.
 *  Thread Starter [zecke](https://wordpress.org/support/users/zecke/)
 * (@zecke)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/put-some-html-code-after-third-item-in-the-loop/#post-4178700)
 * Ok. Thanks. I posted it as a new one

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

The topic ‘Put some html code after third item in the loop’ is closed to new replies.

 * 5 replies
 * 3 participants
 * Last reply from: [zecke](https://wordpress.org/support/users/zecke/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/put-some-html-code-after-third-item-in-the-loop/#post-4178700)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
