WordPress.org

Support

Support » Themes and Templates » Notice: Undefined variable: i in debug mode

Notice: Undefined variable: i in debug mode

  • Hello,

    i get Notice: Undefined variable: i on line 19 which reference to this code

    <?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) == 0) : $wp_query->next_post(); else : the_post(); ?>

    any ideas how to fix that?

    Thanks in advance

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Andrew Nevins

    @anevins

    Forum moderator

    Try;

    <?php
     $i = 0;
     if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) == 0) : $wp_query->next_post(); else : the_post();
    ?>

    You may want to change the zero to one.

    Thanks @andrew works fine with 0, when i put 1 it repeats post number 2 twice.

    Thanks for your help 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Notice: Undefined variable: i in debug mode’ is closed to new replies.
Skip to toolbar