title: using an if statement inside a while with wordpress
body: <p>Hi guys I'm using a while loop to display my posts and while I have posts I want to display the odd and even post numbers differently.  I currently have the following code:</p>
  
  <pre><code>    &lt;div class="container"&gt;
        &lt;?php if ( function_exists('yoast_breadcrumb') ) {
          yoast_breadcrumb('&lt;p id="breadcrumbs"&gt;','&lt;/p&gt;');
        } ?&gt; 
      &lt;/div&gt;
      &lt;?php query_posts('post_type=portfolio&amp;post_status=publish&amp;posts_per_page=8&amp;paged='. get_query_var('paged'));
        if( have_posts() ):
          echo '&lt;div&gt;';
        if ( $wp_query-&gt;have_posts() ) : 
          while ( $wp_query-&gt;have_posts() ) : 
            $wp_query-&gt;the_post();
        $i = 0;
        if($i % 2 == 0)
        {?&gt;
          &lt;div class="class1"&gt;
            html content 1 to go here
          &lt;/div&gt;
          &lt;?php
            $i++;
        }else{
          ?&gt;
          &lt;div class="class2"&gt;
            html content 2 to go here
          &lt;/div&gt;
          &lt;?php $i++; } ?&gt;
          &lt;?php endif; ?&gt;
          &lt;?php endwhile; ?&gt;
          &lt;div class="container"&gt;
            &lt;div class="navigation"&gt;
              &lt;span class="newer"&gt;&lt;?php previous_posts_link(__('« See Previous Case Studies','example')) ?&gt;&lt;/span&gt; 
              &lt;span class="older"&gt;&lt;?php next_posts_link(__('See Next Case Studies »','example')) ?&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/div&gt;  &lt;!-- /.navigation --&gt;
          &lt;?php else: ?&gt;
          &lt;div id="post-404" class="noposts"&gt;
            &lt;p&gt;&lt;?php _e('None found.','example'); ?&gt;&lt;/p&gt;
          &lt;/div&gt;&lt;!-- /#post-404 --&gt;
          &lt;?php endif; wp_reset_query(); ?&gt;
  </code></pre>
  
  <p>I haven't used php for a while, so I'm unsure the best way to do the above. I'm currently getting a few errors relating to syntax such as unexpected end of file or unexpected } on line...</p>
  
  <p>Can anyone figure out where I am going wrong? </p>