Yes you can do that using $wp_query->current_post inside the loop. It returns the current posts index number inside the loop (starting form 0). Have a look at the following code block
<?php
global $wp_query;
while(have_posts()){
the_post();
the_title();
//do your other stuff
if($wp_query->current_post==1){
//do what you want to do after 2nd post
}else if($wp_query->current_post==5){
//do what you want to do after 6th post
}
}
Related Posts:
- How do I get the attributes of a short code from a post?
- Show scheduled posts in archive page
- post__in – Placing content from a foreach loop inside of an array
- loop query exclude meta_key with meta_value
- “Blog pages show at most” in The Loop
- wp_insert_posts Fatal error: Maximum function nesting level of ‘100’ reached, aborting!
- Post Loop not Returning Permalink
- Custom page template
- Get posts that matches specific terms of multiple custom taxonomies
- add_filter() doesn’t work in loop
- The Loop in Static Page
- How can I use get_permalink() outside the loop?
- Content/Excerpt length control for a specific loop?
- Why we use if with while loop?
- Problem the_permalink
- Loop posts only excluding first post
- Loop repeating design pattern
- Create static front-page with 3-5 recent posts
- Customize WooCommerce Product Images (Placement and size) [closed]
- Create a loop that gets pages with their template
- Why is my loop not dynamically grabbing the correct Category and displaying all categorized posts?
- get latest 5 posts and a specific post and sort in a specific order
- How to check if a post exist?
- Query posts if meta key starts with
- 3 Posts in Loop, Show Stickies First
- Loop within a loop (Again) for template
- Why cant you place the Loop outside of the index.php?
- sticky post in custom loop
- Rating system and changing the loop
- Ajax Button to load more Posts into a timeline
- How to target thumbnails of the first post in the loop
- On single.php, fetch 2 posts created after and 2 posts created before in relation to the actual post (using menu_order)
- Problem getting current post tags to show in a widget
- Post classes in the loop are being changed in certain themes
- Exclude page name from loop
- PHP if post is already displayed, then
- How to style first post differently with ‘get_template_part’?
- Include multiple page ids in loop
- in Foreach Loop the Description is not showing?
- 404 Template customization | Want 10 recent Post on the 404.php error page apart from the error Notice
- How to append a query string to pagination?
- For each loop on every word in post
- Display name of taxonomy once
- Use have_comments() for current post instead of last post in loop
- Displaying the first, second, and third posts from a category in separate slides
- Sending mail not working correctly
- WordPress shortcode in content, output in sidebar?
- Using variable in WordPress loop as criteria
- WordPress Alphabetical Sort Loop Issue
- Get_template_part() problem with the_content()
- Altering “posts_per_page” for defaut loop
- Why doesn’t ‘continue’ work in page?
- Fetching posts from wordpress function in ajax
- Saving return value from the_author_posts_link()
- how to run loop in function.php that sends email based on specific conditions?
- How to use this $tax_selection variable in this custom loop?
- Exclude current post ID from loop in sidepbar.php
- loop inside a loop : search for posts in the same category
- How to sort a loop after most viewed
- How to declare a variable in a loop and make it available in the template file
- WordPress posts loop not displaying all posts on blog
- get_page_by_title not working inside fucntions.php
- Bootstrap tabs are not being clicked in WordPress loop
- Get gallery in loop through ajax
- Get a specific size from wp_get_attachment_image_src
- WordPress + Isotope: how to give different widths to each entry?
- hide woocommerce tab if empty
- Get top Page IDs from menu and cycle through their child pages on a scroller
- Show other category posts in single.php
- Why does it loop twice?
- Cant pull in featured Image
- Custom Looping of WordPress Posts
- how to place Post and page content side by side
- Add specific class to featured posts
- Echo Most Recent Sticky Post in Loop?
- Link Button url count php and wordpress
- ACF field not appearing correctly in loop
- Posts are being displayed from old to new, in ascending order
- Loop in taxonomy for terms and post
- WordPress Tags in class
- Query counting excluded category on paged loop
- Using shortcode within shortcode with dynamic variable
- modify default HAVE_POSTS() Loop without inserting new variable (i.e. $loop->HAVE_POSTS)
- Display articles related to a custom field on a page
- The Loop isn’t working
- Changing the loop w/o killing category links
- Custom loop page with post navigation
- Pages with a loop (index, archive) are loading the first image as post_thumbnail
- the loop – how to control whether wp or plug-in runs it
- stuck with template hierarchy
- An action that runs after each post in the loop on index/archive page?
- Modify my code – which takes the first sentence of the post and use it as a h2 tag – to work outside the loop
- How to show only specific tag in wordpress loop
- Different style for first two (sticky) posts
- WooCommerce – Checkout suddenly stops working [closed]
- Want to images load first then title in WordPress loop
- How to add a continuous number to HTML tag attribute value inside The Loop [closed]
- WordPress Not Sorting By Custom Field
- wp_mail sending only once inside foreach loop
- How to use orderby on meta_value when using Pods custom database table storage