It’s not related to WordPress at all, it’s a generic PHP question, hence off-topic here. It’s easy, follow the inline comments, and you can have it. 🙂
<?php
//declare a counter
$counter = 1;
// Start the Loop.
while ( have_posts() ) : the_post();
/*
* Include the post format-specific template for the content. If you want to
* use this in a child theme, then include a file called called content-___.php
* (where ___ is the post format) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
//check the counter and display your content
if( $counter === 3 ) { ?>
<div class="third-div-in-loop">content</div>
<?php }
//update the counter on every loop
$counter++;
endwhile;
Related Posts:
- When should you use WP_Query vs query_posts() vs get_posts()?
- WP_Query by just the id?
- How to get post id of static front page?
- Get post ids from WP_Query?
- How can i retrieve default post per page value? from settings->reading. And total number of posts?
- WP_Query result in form of Rest API results
- Exclude Child Posts from WP_Query
- WP_Query for WooCommerce Products
- WP_Query with two post types, but requiring category on only one of those post types
- Slow SQL_CALC_FOUND_ROWS Query
- How do I exclude all images from a wp_query?
- How to limit the posts
- get_the_title($postID) OR get_the_title()?
- How can I connect to another WP database and use WP_Query?
- datetime picker, timestamps and meta queries
- How to order posts in wp_query by a meta_value of the corresponding author
- How to get sum of meta_values of a meta_key in wp_query according to conditions
- Custom query, works, but I get a “Notice: Undefined offset: 0…”
- How to display 3 different loops in 3 columns on homepage
- Get the post thumbnail with wp_query
- Where to use $post global variable?
- How to display future posts – modified query still yields 404
- Multiple instances of Featured Image Query
- What’s faster? One big query, or several smaller ones?
- Meta Query for specific months
- How to apply filter inside a single wp_query?
- Overwriting posts_per_page in new WP_Query
- Sticky posts are not showing at the top of category posts
- WPDB query – decrypting DB data
- Storing query variable and then using wp_reset_query
- How to use WP_Query without breaking the main Query
- Trouble with wp_reset_postdata() in Admin Panel
- ACF Date Based wp_query
- exclude posts with a specific custom field and value
- Database Queries Optimization with new WP_Query
- query_vars filter not working even though query string parameter is present
- Mysql query and order meta value
- Group and list posts by custom taxonomy
- Show scheduled posts in main loop but not in WP_Query?
- WordPress Pagination changes my template
- wp_query ignoring custom post_status
- Query posts(CPT, pages , hierarchical) by Ancestor ID
- meta_query BETWEEN, but the range is stored in the custom field
- Input check to custom post type query
- Having trouble with WooCommerce Storefront child theme single.php “related posts” modification [closed]
- WordPress pagination not working on template search.php
- Order ascending is ignored in meta query?
- Custom Pagination in Shortcode with WP_Query
- Show all data in database table and make it into an interactive table
- WP Query – Post Thumbnail
- How to filter a query by date in a shortcode?
- Search posts missing a particular custom field
- Query post with meta value in set of values
- Sort by presence of thumbnail
- Link Author URL’s based on a custom field
- embedding shortcodes in php template
- wp-query, pull children of parent page
- Max Posts and Memory Limit
- How to change tag based on metabox value within $wp_query
- What’s missing in this wp_query and meta_query
- Tax Query on product_cat using NOT IN as operator does not exclude that category
- WP_Query orderby
- Using Ajax and WP_Query to load more posts on category page fails
- How to use the Term Object from a custom select field in a query
- Random users always showing same 8 users
- I have problems with the search query using multiple post types
- How to check if logged in user have pending custom post?
- whether a nonce is required for get type and get_query_var?
- How can I re-query post_type and rewrite the url?
- Wp-query and column blocks
- How to query users by post count no less than 10
- Different query result on local and server
- Display 3 levels of categories on page
- How can I show only last year posts in wordpress archive?
- Showing most popular post of week
- Related Post by Tags Code
- I can’t get post based on its postmeta value and key
- Change database image location for transportability
- Combine Tax Archive and Meta_Query in WP_Query
- Get posts by birthday
- Display three sequential posts on each page load, without repeating previous
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- Find by post_meta, then sort by post_meta, then sort by date (wp_posts)
- Optimising amount of calls to custom fields
- Issue in If else condition [closed]
- Pagination not working with WP_QUERY
- The sorting of posts by a meta_query with two keys fails while separated as single queries it works
- Custom Content Slider stop duplicate
- Extract video content from post to display on front page
- Hierarchical List Pages as a table
- WP_Query with several meta_query-statements and order by meta_value
- Second wp_query doesn’t appear to be working
- difference between methods of query
- post__in not recognizing multiple IDs
- Related posts with WP_Query
- Carousel slider with WP_Query to show 3 posts on each slide
- how to use transient method?
- Pre_get_post on CPT archive page
- WP_Query – order with usort by custom meta
- Get posts that were most recently tagged