You could just make an easy counter – Untested though.
<?php else : ?>
<?php global $wp_query; ?>
<?php $ads = 0; ?>
<?php if ($ads < 3 && (($wp_query->current_post + 1) % 5 == 0 )): ?>
<div class="box">
<adsense code>
</div>
<?php $ads++; ?>
<?php endif; ?>
Related Posts:
- Displaying post per day
- Guidance with The Loop for CMS
- Display only text to WordPress loop without loosing the text formatting
- Post from one loop in different containers?
- Custom Loop Pagination on WordPress
- delete an array element when its date expires
- How to change post count in wordpress loop?
- How can I loop into two different DIVS without repeating the DIVs
- User Defined order on get_categories?
- get understrap pagination to work with custom query
- Woocommerce – How to get products which have a sale between 20% to 40%? [closed]
- Displaying Only Certain Tags in Loop
- When would you use $_post instead of $post?
- Way to display “Yesterday”, “Today”
- How can i display post loop in table format?
- Must Use Plugin Causing Query Error
- Advanced Custom Fields: Post Object – Not returning data [closed]
- multiple if statements [closed]
- How to select WooCommerce products by post_meta and order them
- have_posts() execution failure
- How does the ternary operator work in the wordpress loop post?
- How can I add multiple ‘tax_query’ arrays via a loop?
- Blog posts repeat
- How to set variable, pass it to a partial file and remove it after?
- how to refresh div on template part?
- Can’t find infinite loop cause
- Checkbox doesn’t stay checked, conten
- List posts that don’t have a specific tag?
- Can we count the WordPress Loop
- Add content after the first post in WP Loop
- Display an image if odd number of posts in grid
- How to loop through all the attached images in a post, and get their url one by one
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- 2nd page displaying the exact same posts as my first page (minus the very first post)
- Is the 404 page automatically displayed if a loop returns nothing?
- Last class on last headline?
- Show recent posts starting at a specific number archive
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- Issue with custom loop in Archive page
- use loop to return blog details
- WP Query Leads to 502 Bad Gateway (Timeout Because Query Takes Too Long)
- home.php show blog posts as grid view
- How to add post meta in while loop?
- Echoing a CSS class based on category of post in a list
- Calling function in loop causes repeat data
- WordPress call post-ID in jquery
- How to Generate a list of Most Commented post?
- How to pick “full/thumbnail” images in the loop?
- How to Fix an Archive.php That Displays All Posts?
- List all anchor links on a page
- Php code error in wordpress if else statements [closed]
- How to add ASCII symbol after each recent post [closed]
- pagination broken – clicking next displays “page not found”
- Search.php gets metadata from first post
- the_post(); prints out style text into my HTML?
- How do I get pagination for get_posts() in WordPress or do I have to rewrite the whole code?
- Check if current post in loop is last on current page
- update_user_meta as multiple value but with same meta key
- adding or removing endforeach; throws error!
- Adding PHP to an if else loop
- Accordion headings cuts off to second line on collapsing a accordion heading (used acf repeater)
- WordPress Recent Posts – Loop
- ACF background-color per post in a WordPress loop
- Advertisement in Loop Posts wordpress
- Filter loop by ‘price’ with meta_query
- PHP for loop not working as intended
- Adding custom PHP to existing loop in Genesis
- How to Pass Current Taxonomy Terms into new WP_Query?
- Problems with the WordPress loop [closed]
- WordPress while loop with aphabetic counting like one, two, three
- For each 3 posts, show a different post type
- Add post class in custom loop (WP_QUERY)
- Loop returns more items than exist?
- Modify category archive page loop on functions.php
- WP_Post is not from correct array
- Post formating on Home page
- divide custom field values in div every two values
- I want my wordpress loop to only display posts of the standard format
- Automatically create a loop for post ID
- Inserting A Feed and Sidebar into an HTML Page
- Pagination on Custom Loop
- What is the best way to get the first few post from WordPress in different divs using a loop?
- Transient Loop Not working as expected
- Advanced Taxonomy query, with 3 post types
- Custom single.php files for different post formats
- Troubleshooting “loopback requests that take too long”
- Why does a meta_query break this WP_Query?
- is there away to hide php code in wordpress not to show in PAGES
- Loop on a wordpress Page instead of content coming from the WP text editor
- How to create a loop where loop changes every post?
- Help with if/else loop [closed]
- $_html is empty when var dumped
- I want to show image from custom field image on my custom page template
- Count the number of matching post names in foreach loop
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress
- How to show correct td of table tags in wp_query loop
- fetch from an external api call and display results in page
- When a foreach loop is used multiple times in blocks, is there a way to ensure a variable always has a unique value?
- Custom theme on multisite has issues with standard loop output
- How to get the post title inside a custom block in a loop? block.js