You can check your position within the loop using the current_post
var of the $wp_query
object, and insert markup at a specific spot or at some interval. A simple example:
while( have_posts() ):
the_post();
the_title();
the_excerpt();
// if current_post is 1, insert the div
// note that current_post starts at 0,
// so this will be after the second post's content
if( 1 == $wp_query->current_post ):
echo '<div>My div!</div>';
endif;
endwhile;
Related Posts:
- Keep featured content post in homepage with original order
- How to show related posts by category
- the_author() returns empty string
- Display all posts from specific categories on a page
- How to exclude latest x posts from a paginated query?
- Display content from a specific category
- How to display posts by current user/author in a custom page template?
- post_name empty after wp_insert_post
- WordPress Posts Out Of Order after 3.1 Update
- Query only Posts from Both of Two Category?
- Only display posts with comments
- WordPress get posts by date without query_posts
- How to Display Post View Count
- Different amount of posts on homepage than paged pages
- Featured Posts for Category Pages
- Cannot Update A Post, 404 Error
- Hiding posts in a list from specified categories
- How would I get 1 latest post from a query for 5 posts?
- Filter Posts By Tag
- Can I set and show “important” post in my blog?
- Exclude posts with empty post_content in wp_query
- Create dropdown list post
- I would like to give special promotion for the first 100 posts in my blog? Can anyone tell me how to do that?
- previewing my posts on static page?
- Exclude newest post from category X but show rest
- Reset Popular post query?
- Inserting custom data to the_post() during loop
- is there a way to show the the post title after the image?
- Display posts with tag that matches current post title
- Category Foreach keeps looping?
- Blog post per page setting conflicting with custom WP_Query?
- How to exclude latest x posts from a paginated query?
- Random ajax load only works with posts_per_page set to -1
- Display an author’s posts on his own author page
- How to make multiple sections in home pulling posts category wise?
- wp_posts table: safely remove unused columns to save database storage
- Query Posts by Custom Field
- Order posts alphabetically: how to set order=asc in mysql query?
- How to order posts in an arbitrary order?
- Display Posts on Custom Page
- How to get posts from a current post’s month?
- Wrong post title displayed from loop
- While loop articles – if statement order
- Conditionals if tags exist?
- WordPress website loads more posts than expected
- Get the amount of posts on a current page
- Posts – display all posts except a post by an ID
- Counter is skipping post when I still want it visible [closed]
- query post limits
- why the same code got different results when using query_posts in functions.php and index.php
- Archive template combined with post slider and regular posts
- How to get posts published on the latest date?
- How to only publish posts with image in it
- How to check in functions.php if there is data in a WP_Query?
- Post Filtering by GET URL parameters
- wp_query with ajax
- WP_Query: Show 10 posts in date order, first three random
- Custom posts listing widget always returns 1 extra result
- Get post by tag
- Random posts that always include a particular post?
- Bootsrap carousel for post
- All categories displays the same posts
- Get postlist for each category using query_posts?
- Query function not executed between element [closed]
- Echo the number of posts being displayed
- Exclude a category of posts in author template
- Display specific posts on home page
- WordPress displays post on subcategory only
- Trying to query all posts in category 4
- Get posts from current category?
- Change content off every sixth element
- Move position in post list for a custom checkbox column
- get posts, run a custom query, and join the results
- Show posts from two specific category in WP_Query
- How to create loop of posts except post ID defined via ACF field
- Displaying all posts from other sites on the network on one site
- Multisite how to display merged posts from two sites and sort by latest date?
- How to display particular categorie’s post which associated to specific user?
- wp_query args with relation
- Manipulate query to show specific post
- How to correctly escape data
- Use special template for the first post in the loop
- Blog posts not displaying on blog posts page
- Repeating post how to solve this
- Sort Events by Venue Title – Sort Post set by related post ids
- Get posts by category or author
- show latest authors blog post
- get “read more” with custom DB query like you would with WP Query
- How to get only current images of a post
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- How to pass multiple checkbox values to wordpress query?
- How to get all post titles starting with numbers and symbols?
- How to inject a post within a loop
- How to get alphabetic listing x other posts, based on first letter post?
- wp_query select if have comments
- Creating pages and getting their values from the database table
- wp trim function not working
- query_posts different amount of posts per page [duplicate]
- Sort Posts Alphabetically Based on Specific Category (Divi)
- How to change url of posts?