Title: Code change if is paged
Last modified: August 30, 2016

---

# Code change if is paged

 *  Resolved [Dot22](https://wordpress.org/support/users/dot22/)
 * (@dot22)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/code-change-if-is-paged/)
 * Hi! I’m trying to get some piece of code to work but don’t have any result. The
   following code insert a div between two posts on the index page, but I need to
   change that on pagination.
 *     ```
       <?php
       if (($wp_query->current_post%2 == 0 )) {
          echo '<div style="background-color: #ffcc00; width: 100%; display: block; height: 25px; clear: both; float: left;"></div>';
       }
       ?>
       ```
   
 * If is front page the value of wp_query is correct, but if is page 2 it must be“(
   $wp_query->current_post+1)%2 == 0”. How can I do that and not break the function?
 * Thanks in advance! =)

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/code-change-if-is-paged/#post-6885188)
 * try:
 *     ```
       <?php
       if ( ( !is_paged() && $wp_query->current_post%2 == 0 ) || ( is_paged() && ($wp_query->current_post+1)%2 == 0 ) ) {
          echo '<div style="background-color: #ffcc00; width: 100%; display: block; height: 25px; clear: both; float: left;"></div>';
       }
       ?>
       ```
   
 *  Thread Starter [Dot22](https://wordpress.org/support/users/dot22/)
 * (@dot22)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/code-change-if-is-paged/#post-6885204)
 * Awesome Michael, it works like a charm! Thank you very much! =D

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

The topic ‘Code change if is paged’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Dot22](https://wordpress.org/support/users/dot22/)
 * Last activity: [10 years, 5 months ago](https://wordpress.org/support/topic/code-change-if-is-paged/#post-6885204)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
