• Hello

    I’ve my query done with 3 posts.

    I open the loop but I don’t want to do same things for my 3 posts.

    How can i tell WordPress I want to write the second or the third post ?

    thx all

Viewing 1 replies (of 1 total)
  • You can use a counter in the loop to do different things for each post. The code would look something like this:

    query_posts( array('posts_per_page' => 22) );
    if (have_posts()) : while (have_posts()) : the_post();
    
       if ( ++$counter == 1 ) :
          // Code for first post here
          echo "<p>Processing post 1</p>";
       elseif ( $counter == 2 ) :
          // Code for second post here
          echo "<p>Processing post 2</p>";
       elseif ( $counter == 3 ) :
          // Code for third post here
          echo "<p>Processing post 3</p>";
       endif;
    
    endwhile; endif;
Viewing 1 replies (of 1 total)
  • The topic ‘Navigate through posts inside the loop’ is closed to new replies.