When the loop is complete, have_posts()
rewinds it back by calling the rewind_posts()
method of the $wp_query
object, see here.
Here’s another (more simple?) setup that you could try:
while( have_posts()): the_post();
if ( 0 == $wp_query->current_post ):
// post 1
elseif ( 1 == $wp_query->current_post ):
// post 2
else:
// other posts
endif;
endwhile;
wp_reset_postdata();
where we use the current_post
property of the global $wp_query
object to keep the track of the current post.
Related Posts:
- Display Authors in a grid loop
- Display more than 10 posts on author.php file
- Displaying posts limit: can’t get pagination to display [duplicate]
- Counting the posts of a custom WordPress loop (WP_Query)?
- Get post content from outside the loop
- Is there any difference between the_title() and echo get_the_title()?
- Using the Loop to show all levels of subpages under a parent page? Halfway there
- Cleanest Way to Select Every Second Element in a Loop?
- Pagination not working on home page
- How to Change Loop to Order Posts by Views (using wp-postviews plugin)
- is_home, and is_front_page conditional problem
- Is `query_posts` really slower than secondary query?
- Are there any scenarios where the query_posts may be used?
- Display subpages under parent page as a list within a loop
- When to use wp_reset_postdata();
- Why do themes have `while( have_posts() )` in templates like single.php?
- Exclude category by slug for for each loop
- Related Posts loop – offset
- Too many nested wp_query loops in this hypothetical query?
- WordPress Loop Through Particular Pages
- Showing current subcategory
- Display date only once for a each set of posts relating to that date
- WordPress Loop – Style rows of posts differently
- Generating dynamic Tabs with multiple query post loop
- How do I override part of the main loop in my child theme?
- Chopping up a large ajax request of around 200 posts [closed]
- Combining the_excerpt with the_content
- Better way to display posts from specific categories, in a grid layout
- Infinite Redirect Loop after moving to subdirectory
- Loop after page content
- the_excerpt not showing posts
- WordPress Loop – Not returning projects in specific category
- Next and Previous loop
- add most viewed post by google analytic in loop [closed]
- Query reset problem or flawed code to enable custom post type query
- Sort posts by most recently modified
- Exclude posts from main loop based on meta value
- Using an ACF field from a page within a post loop?
- trouble calling an import class from an action in a plugin before wp_cron executes
- Blog page Server error 500 with stick post loop in query.php
- Obtain page data and use regular loop
- How can I load posts starting from, and including, the current post?
- How to fix pagination for custom loops?
- Show all posts using the template page and the loop?
- ‘Auto Draft’ Post showing in wordpress loop
- How do I display an image before the first post of the loop when I’m using get_template_part?
- Why does `inclusive` not work in this wordpress loop?
- How do I automate multiple category loops?
- Multiple get_posts() queries on one page
- Custom loop not working
- Loop inside query
- In Custom page – next_posts_link Not working while previous_posts_link is working
- Escape current post from loop
- Why isn’t my multiple loops working?
- How can I display other user avatars on an author profile page?
- something strange is happening to my code
- How to modify search.php to not show pages only show posts
- How do I display the latest posts from three different categories?
- facebook like, tweet and google+1 buttons inside the loop on home, archive and search pages and missing facebook like buttons
- Loop Offset for tag based “Related Posts”
- How do I put my frontpage featured image in a page template for home.php?
- Randomly display post based on meta value. (Kind of Priority/Weight)
- How to print redux gallery feilds id? [closed]
- Why the first with flexslider appears as blank on my code?
- Rendering pages
- How can have a conditional template tag based on the main loop within a secondary loop with new WP_Query(), using get_template_part()
- WP_Query is only looping home page, not pages
- How to filter posts by category INSIDE the loop
- static page with multiple loops breaks post pagination
- new custom theme – posts displaying on top of one another
- Help with if and else statement
- Pagination in author, category, archive and tags pages does not work
- Building a form with WordPress, and also pulling that data for a user page
- Custom Header added within Dashboard pages, is this possible with custom template files?
- Loop order issue with Ajax filter
- Adding a second loop breaks everything
- Custom Query with Sticky Posts
- is it bad to copy the loop for a template?
- I want to load post in bootstrap Modal dynamically
- Why my loop is repeat?
- Excerpts not showing on main page
- Return only one post format in index.php [duplicate]
- How to display just video post format?
- Is it possible to get a post ID of a 2 different custom post types loop embedded in the same post to perform update_post_meta from the frontend?
- Loop shows post 5 times in a query
- How to execute custom loop before loop content?
- Make custom WordPress comments list
- Sorting posts to make those with post thumbnail show up first
- Best way to check if a post with specific meta exists
- Return only content in excerpt field in loop
- Default Template infinite loop of Title
- Buddypress Group Activity Loop Filter activity type [closed]
- get_posts and wp_autop (remove filter)
- Trouble preventing duplicate posts between 2 loops on homepage
- Change the way wordpress outputs images or image galleries
- How can I access ‘key’ and ‘value’ from an array in a for loop?
- How to get current page id and compare it to looped pages inside the same page?
- posts_nav_link() not working on index.php
- Error in Wordprewss loop for page template [closed]
- Tags outside the loop